Here you can find the source of toJson(Object object, String dateFormat)
public static String toJson(Object object, String dateFormat)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class Main { public static String toJson(Object object) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true); try {/*from ww w . j a v a 2s . c om*/ return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object); } catch (Exception e) { e.printStackTrace(); } return null; } public static String toJson(Object object, String dateFormat) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(new SimpleDateFormat(dateFormat)); objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true); try { return objectMapper.writeValueAsString(object); } catch (Exception e) { e.printStackTrace(); } return null; } }