Java Object to Json toJSON(T obj)

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

Description

to JSON

License

Apache License

Declaration

public static <T> String toJSON(T obj) 

Method Source Code


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

import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {

    public static <T> String toJSON(T obj) {
        String json = null;/*www .  j  av  a  2s . c o  m*/
        try {
            ObjectMapper mapper = new ObjectMapper();
            json = mapper.writeValueAsString(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
}

Related

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