Java Object to Json toJson(Object value)

Here you can find the source of toJson(Object value)

Description

to Json

License

Open Source License

Declaration

public static final String toJson(Object value) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class Main {
    private static final ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);

    public static final String toJson(Object value) {
        try {/*from ww w.  ja v a 2s  .c  om*/
            return mapper.writeValueAsString(value);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. toJSON(Object obj)
  2. toJson(Object obj)
  3. toJson(Object object)
  4. toJson(Object object)
  5. toJson(Object object)
  6. toJSON(T obj)
  7. toJSON(T obj)
  8. toJSON(T valueType)
  9. toJsonString(Object obj)