This repository has been archived on 2021-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
2020-11-18 18:06:38 +01:00
|
|
|
package org.gcube.application.geoportal.service.utils;
|
|
|
|
|
|
|
|
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.datatype.jsr310.JavaTimeModule;
|
|
|
|
|
|
|
|
public class Serialization {
|
|
|
|
|
|
|
|
public static ObjectMapper mapper;
|
|
|
|
|
|
|
|
static {
|
|
|
|
mapper=new ObjectMapper();
|
|
|
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
|
|
|
mapper.registerModule(new JavaTimeModule());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> T read(String jsonString,Class<T> clazz) throws JsonProcessingException, IOException {
|
|
|
|
return mapper.readerFor(clazz).readValue(jsonString);
|
|
|
|
}
|
2020-11-19 17:38:56 +01:00
|
|
|
public static String write(Object toWrite) throws JsonProcessingException {
|
|
|
|
return mapper.writeValueAsString(toWrite);
|
|
|
|
}
|
2020-11-18 18:06:38 +01:00
|
|
|
}
|