Java Object to Json obj2Json(Object obj)

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

Description

obj Json

License

Apache License

Declaration

public static String obj2Json(Object obj) 

Method Source Code

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

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

public class Main {

    public static String obj2Json(Object obj) {
        try {/*from  ww  w . j av  a2  s  .co m*/
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter();
            return ow.writeValueAsString(obj);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. object2Jason(Object obj)
  2. objectToString(StringBuilder bld, ObjectNode node, int depth, boolean newLine)
  3. objToJson(Object obj)
  4. toJson(List list)