Here you can find the source of toJsonString(Object obj)
Parameter | Description |
---|---|
obj | a parameter |
public static String toJsonString(Object obj)
//package com.java2s; //License from project: Open Source License import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { private final static ObjectMapper mapper = new ObjectMapper(); /**/*from ww w. j a v a 2s.co m*/ * Serializes an object to Json string. * * @param obj * @return */ public static String toJsonString(Object obj) { try { return obj != null ? mapper.writeValueAsString(obj) : null; } catch (JsonProcessingException e) { throw new RuntimeException(e); } } }