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

com.sentenial.rest.client.utils.JsonUtils Maven / Gradle / Ivy

There is a newer version: 1.0.27.RELEASE
Show newest version
package com.sentenial.rest.client.utils;

import java.text.SimpleDateFormat;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {

	public static final ObjectMapper objectMapper = new ObjectMapper()
			.setSerializationInclusion(Include.NON_NULL)
			.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN)
			.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));

	public static  T fromJson(String json, Class clazz) {
		try {
			return objectMapper.readValue(json, clazz);
		} catch (Exception e) {
			throw new JsonTransformationException(e);
		} 
	}

	public static String toJson(Object src) {
		
		try {
			return objectMapper.writeValueAsString(src);
		} catch (Exception e) {
			throw new JsonTransformationException(e);
		} 
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy