2020-11-18 18:06:38 +01:00
|
|
|
package org.gcube.application.geoportal.service.utils;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2020-11-23 18:31:20 +01:00
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.Collection;
|
2020-11-18 18:06:38 +01:00
|
|
|
|
|
|
|
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-23 18:31:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// As DB String
|
|
|
|
|
|
|
|
public static String asString(Collection<?> coll) {
|
|
|
|
if(coll==null||coll.isEmpty()) return "";
|
|
|
|
StringBuilder builder=new StringBuilder();
|
|
|
|
for(Object t : coll) {
|
|
|
|
builder.append(t.toString() +",");
|
|
|
|
}
|
|
|
|
return builder.substring(0, builder.lastIndexOf(","));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final DateTimeFormatter FULL_FORMATTER=DateTimeFormatter.ofPattern("uuuuMMdd_HH-mm-ss");
|
2020-11-18 18:06:38 +01:00
|
|
|
}
|