Here you can find the source of toJson(Object object)
Parameter | Description |
---|---|
object | a parameter |
public static String toJson(Object object)
//package com.java2s; //License from project: Apache License import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.text.SimpleDateFormat; public class Main { /**//from www .j av a 2s.co m * * @param object * @return */ public static String toJson(Object object) { ObjectMapper mapper = new ObjectMapper(); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); try { return mapper.writeValueAsString(object); } catch (JsonProcessingException e) { return ""; } } }