Java Json Create toJson(Object object)

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

Description

to Json

License

Apache License

Parameter

Parameter Description
object a parameter

Declaration

public static String toJson(Object object) 

Method Source Code


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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.text.SimpleDateFormat;

public class Main {
    /**//from  www  .j  av a  2s.co  m
     *
     * @param object
     * @return
     */
    public static String toJson(Object object) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            return mapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            return "";
        }
    }
}

Related

  1. getJson(T t)
  2. object2JsonDateSerializer(Object obj, final String dateformat)
  3. toBean(Class clazz, String json)
  4. toJson(E e)
  5. toJSON(Map map)
  6. toJson(Object object, String dateFormat)
  7. toJsonString(Map map)
  8. toList(String json, Class clz)
  9. toLocalJson(Object value, int depth)