commit 67aa9c414784e95f982354370140c9c4e8565576
Author: Pavel Fidransky <pavel.fidransky@yoso.fi>
Date:   Sat Jun 27 20:17:20 2020 +0200

    re #41 replace own (de)serializers of java.time.* classes by Jackson implementation

diff --git a/server/src/main/java/org/danekja/ymanager/RESTConfiguration.java b/server/src/main/java/org/danekja/ymanager/RESTConfiguration.java
index 0114bf5..a5dcde5 100644
--- a/server/src/main/java/org/danekja/ymanager/RESTConfiguration.java
+++ b/server/src/main/java/org/danekja/ymanager/RESTConfiguration.java
@@ -1,21 +1,20 @@
 package org.danekja.ymanager;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
 import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
-import java.io.IOException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -39,99 +38,19 @@ public class RESTConfiguration implements WebMvcConfigurer {
         ObjectMapper mapper = new ObjectMapper();
         mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
 
+        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
+        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
+
         SimpleModule module = new SimpleModule();
-        module.addDeserializer(LocalDate.class, new LocalDateDeserializer());
-        module.addSerializer(LocalDate.class, new LocalDateSerializer());
-        module.addDeserializer(LocalTime.class, new LocalTimeDeserializer());
-        module.addSerializer(LocalTime.class, new LocalTimeSerializer());
-        module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer());
-        module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer());
+        module.addDeserializer(LocalDate.class, new LocalDateDeserializer(dateFormatter));
+        module.addSerializer(LocalDate.class, new LocalDateSerializer(dateFormatter));
+        module.addDeserializer(LocalTime.class, new LocalTimeDeserializer(timeFormatter));
+        module.addSerializer(LocalTime.class, new LocalTimeSerializer(timeFormatter));
+        module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(dateTimeFormatter));
+        module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(dateTimeFormatter));
         mapper.registerModule(module);
 
         return mapper;
     }
-
-    class LocalDateDeserializer extends StdDeserializer<LocalDate> {
-
-        private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
-
-        LocalDateDeserializer() {
-            super(LocalDate.class);
-        }
-
-        @Override
-        public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
-            return LocalDate.parse(jsonParser.readValueAs(String.class), formatter);
-        }
-    }
-
-    class LocalDateSerializer extends StdSerializer<LocalDate> {
-
-        private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
-
-        LocalDateSerializer() {
-            super(LocalDate.class);
-        }
-
-        @Override
-        public void serialize(LocalDate value, JsonGenerator generator, SerializerProvider provider) throws IOException {
-            generator.writeString(value.format(formatter));
-        }
-    }
-
-    class LocalTimeDeserializer extends StdDeserializer<LocalTime> {
-
-        private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
-
-        LocalTimeDeserializer() {
-            super(LocalTime.class);
-        }
-
-        @Override
-        public LocalTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
-            return LocalTime.parse(jsonParser.readValueAs(String.class), formatter);
-        }
-    }
-
-    class LocalTimeSerializer extends StdSerializer<LocalTime> {
-
-        private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
-
-        LocalTimeSerializer() {
-            super(LocalTime.class);
-        }
-
-        @Override
-        public void serialize(LocalTime value, JsonGenerator generator, SerializerProvider provider) throws IOException {
-            generator.writeString(value.format(formatter));
-        }
-    }
-
-    class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
-
-        private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
-
-        LocalDateTimeSerializer() {
-            super(LocalDateTime.class);
-        }
-
-        @Override
-        public void serialize(LocalDateTime value, JsonGenerator generator, SerializerProvider provider) throws IOException {
-            generator.writeString(value.format(formatter));
-        }
-    }
-
-    class LocalDateTimeDeserializer extends StdDeserializer<LocalDateTime> {
-
-        private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
-
-        LocalDateTimeDeserializer() {
-            super(LocalDateTime.class);
-        }
-
-        @Override
-        public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
-            return LocalDateTime.parse(jsonParser.readValueAs(String.class), formatter);
-        }
-    }
 }
