Java Object to Json toJson(Object o)

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

Description

to Json

License

Apache License

Declaration

public static String toJson(Object o) 

Method Source Code

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

import java.util.TimeZone;
import com.fasterxml.jackson.databind.DeserializationFeature;

import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {

    public static String toJson(Object o) {
        try {/* w w w. j  av a  2s.c  o  m*/
            return getObjectMapper().writeValueAsString(o);
        } catch (Exception e) {
            e.printStackTrace();
            return "<exception>";
        }
    }

    public static ObjectMapper getObjectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        return mapper;
    }
}

Related

  1. objectToString(StringBuilder bld, ObjectNode node, int depth, boolean newLine)
  2. objToJson(Object obj)
  3. toJson(List list)
  4. toJson(Object dto)
  5. toJson(Object message)
  6. toJson(Object o)
  7. toJSON(Object obj)
  8. toJSON(Object obj)
  9. toJson(Object obj)