All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.swagger.v3.core.util.Json Maven / Gradle / Ivy

There is a newer version: 62
Show newest version
package io.swagger.v3.core.util;

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.guicedee.guicedinjection.GuiceContext;

import static com.guicedee.guicedinjection.interfaces.ObjectBinderKeys.*;

public class Json
{

	private static ObjectMapper mapper;

	public static String pretty(Object o)
	{
		try
		{
			return pretty().writeValueAsString(o);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public static ObjectWriter pretty()
	{
		return mapper().writer(new DefaultPrettyPrinter());
	}

	public static ObjectMapper mapper()
	{
		if (mapper == null)
		{
			mapper = ObjectMapperInstance;
		}
		return mapper;
	}

	public static void prettyPrint(Object o)
	{
		try
		{
			System.out.println(pretty().writeValueAsString(o)
			                           .replace("\r", ""));
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy