Java Object to Json toJSON(Object obj)

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

Description

to JSON

License

Open Source License

Declaration

public static String toJSON(Object obj) throws JsonProcessingException 

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.ObjectMapper;

public class Main {
    public static String toJSON(Object obj) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return mapper.writeValueAsString(obj);
    }/* w w  w .jav a 2 s. c om*/
}

Related

  1. toJson(Object dto)
  2. toJson(Object message)
  3. toJson(Object o)
  4. toJson(Object o)
  5. toJSON(Object obj)
  6. toJson(Object obj)
  7. toJson(Object object)
  8. toJson(Object object)
  9. toJson(Object object)