Java Object to Json toJson(Object object)

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

Description

to Json

License

Apache License

Declaration

public static String toJson(Object object) 

Method Source Code

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

import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    private static ObjectMapper objectMapper = new ObjectMapper();

    public static String toJson(Object object) {
        try {//  ww  w  .  ja v a2  s . c  om
            if (object == null) {
                return null;
            }
            return objectMapper.writeValueAsString(object);
        } catch (Exception e) {
            return null;
        }

    }
}

Related

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