geoportal-data-common/src/main/java/org/gcube/application/geoportalcommon/SerializerUtil.java

33 lines
1.1 KiB
Java

package org.gcube.application.geoportalcommon;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
public class SerializerUtil {
private static ObjectMapper mapper;
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.registerModule(new JavaTimeModule());
SimpleModule s=new SimpleModule();
mapper.registerModule(s);
}
public static <T> T read(String jsonString,Class<T> clazz) throws JsonProcessingException, IOException {
return mapper.readerFor(clazz).readValue(jsonString);
}
}