com.askfast.util.JSONUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of askfast-api-java Show documentation
Show all versions of askfast-api-java Show documentation
AskFast Library to use the AskFast system
package com.askfast.util;
import java.util.Collection;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JSONUtil
{
// private static final Logger log = Logger.getLogger( JSONUtil.class.getName() );
public static T deserialize( String jsonString, Class DeserializeClass )
throws Exception
{
T deserializedEntity = null;
if ( jsonString != null && !jsonString.isEmpty() )
{
deserializedEntity = new ObjectMapper().readValue( jsonString, DeserializeClass );
}
return deserializedEntity;
}
public static String serialize( Object objectToBeSerialized ) throws Exception
{
ObjectMapper oMapper = new ObjectMapper();
oMapper.setSerializationInclusion( Include.NON_NULL );
String result = null;
if ( oMapper.canSerialize( objectToBeSerialized.getClass() ) )
{
result = oMapper.writeValueAsString( objectToBeSerialized );
}
return result;
}
public static String toCDLString(Collection list) throws Exception {
return serialize(list).replace( "[", "" ).replace("]", "").replace( "\"", "" );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy