Java Object to Json object2Jason(Object obj)

Here you can find the source of object2Jason(Object obj)

Description

object Jason

License

Apache License

Declaration

public static String object2Jason(Object obj) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    private static ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(Include.NON_NULL);

    public static String object2Jason(Object obj) {
        try {//from  ww  w . ja  va  2s.  co  m
            return objectMapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            return null;
        }
    }
}

Related

  1. obj2Json(Object obj)
  2. objectToString(StringBuilder bld, ObjectNode node, int depth, boolean newLine)
  3. objToJson(Object obj)
  4. toJson(List list)
  5. toJson(Object dto)