Java Object to Json toJsonString(Object obj)

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

Description

Utiliza Object Mapper do Jackson para transformar objeto pojo JAVA em string JSON.

License

Open Source License

Parameter

Parameter Description
obj a parameter

Return

String json

Declaration

public static String toJsonString(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    /**//from  w  ww. j a  v a 2s.  c  o  m
     * Utiliza Object Mapper do Jackson para transformar objeto pojo JAVA
     * em string JSON.
     * @param obj
     * @return String json
     */
    public static String toJsonString(Object obj) {
        ObjectMapper mapper = new ObjectMapper();
        String json = null;
        try {
            json = mapper.writeValueAsString(obj);
        } catch (JsonProcessingException jpe) {
            jpe.printStackTrace();
        }
        return json;
    }
}

Related

  1. toJson(Object value)
  2. toJSON(T obj)
  3. toJSON(T obj)
  4. toJSON(T valueType)
  5. toJsonString(Object obj)
  6. toJSONString(Object object, boolean camelCaseToLowerCaseWithUnderscores)
  7. toJsonString(T value)
  8. writeJSON(HashMap data)
  9. writeValueAsBytes(Object value)