Java Object to Json toJSONString(Object object, boolean camelCaseToLowerCaseWithUnderscores)

Here you can find the source of toJSONString(Object object, boolean camelCaseToLowerCaseWithUnderscores)

Description

to JSON String

License

Apache License

Declaration

public static String toJSONString(Object object, boolean camelCaseToLowerCaseWithUnderscores) throws Exception 

Method Source Code

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

import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
    private final static ObjectMapper LCWU_OBJECT_MAPPER = new ObjectMapper();

    public static String toJSONString(Object object, boolean camelCaseToLowerCaseWithUnderscores) throws Exception {
        ObjectMapper mapper = camelCaseToLowerCaseWithUnderscores ? LCWU_OBJECT_MAPPER : OBJECT_MAPPER;
        return mapper.writeValueAsString(object);
    }/*from  w w w.  j av a2s . c  o m*/

    public static String toJSONString(Object object) throws Exception {
        return toJSONString(object, false);
    }
}

Related

  1. toJSON(T obj)
  2. toJSON(T obj)
  3. toJSON(T valueType)
  4. toJsonString(Object obj)
  5. toJsonString(Object obj)
  6. toJsonString(T value)
  7. writeJSON(HashMap data)
  8. writeValueAsBytes(Object value)
  9. writeValueAsIndentString(Object value)