Here you can find the source of toPrettyPrintJSON(Object object)
public static String toPrettyPrintJSON(Object object)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014, 2017 Open Door Logistics (www.opendoorlogistics.com) * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/lgpl.txt ******************************************************************************/ import java.io.StringWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class Main { public static String toPrettyPrintJSON(Object object) { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // disable this to get data times etc out in ISO 8601 format (which is close to a standard) mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.enable(SerializationFeature.INDENT_OUTPUT); StringWriter writer = new StringWriter(); try {//from w w w. ja va2 s . com mapper.writeValue(writer, object); } catch (Exception e) { throw new RuntimeException(e); } return writer.toString(); } }