Fixed serialisation of cropId and startDate
This commit is contained in:
@@ -2,8 +2,10 @@ package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -29,9 +31,12 @@ public class JsonGardenPlan implements GardenPlan {
|
||||
private final static JavaTimeModule timeModule = new JavaTimeModule();
|
||||
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
||||
static {
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yy-MM-dd");
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDateDeserializer dateDeserializer = new LocalDateDeserializer(dateFormat);
|
||||
LocalDateSerializer dateSerializer = new LocalDateSerializer(dateFormat);
|
||||
|
||||
timeModule.addDeserializer(LocalDate.class, dateDeserializer);
|
||||
timeModule.addSerializer(LocalDate.class, dateSerializer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,6 +128,7 @@ public class JsonGardenPlan implements GardenPlan {
|
||||
try {
|
||||
new ObjectMapper()
|
||||
.registerModule(timeModule)
|
||||
.registerModule(new Jdk8Module())
|
||||
.writeValue(new File(dataSource.toURI()), cropMap.values());
|
||||
} catch (URISyntaxException e) {
|
||||
// TODO: Log
|
||||
|
||||
Reference in New Issue
Block a user