Changeset 5:cd96119c88bb

Added date serializer
author unexist
date Wed, 10 Feb 2021 16:12:35 +0100
parents f4313c0d97ca
children 2e6cbf140ff8
files src/main/java/dev/unexist/showcase/todo/domain/todo/DueDate.java src/main/java/dev/unexist/showcase/todo/infrastructure/serializer/DateSerializer.java
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/dev/unexist/showcase/todo/domain/todo/DueDate.java	Wed Feb 10 16:12:18 2021 +0100
+++ b/src/main/java/dev/unexist/showcase/todo/domain/todo/DueDate.java	Wed Feb 10 16:12:35 2021 +0100
@@ -11,10 +11,16 @@
 
 package dev.unexist.showcase.todo.domain.todo;
 
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import dev.unexist.showcase.todo.infrastructure.serializer.DateSerializer;
+
 import java.time.LocalDate;
 
 public class DueDate {
+    @JsonSerialize(using = DateSerializer.class)
     private LocalDate start;
+
+    @JsonSerialize(using = DateSerializer.class)
     private LocalDate due;
 
     public LocalDate getStart() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/dev/unexist/showcase/todo/infrastructure/serializer/DateSerializer.java	Wed Feb 10 16:12:35 2021 +0100
@@ -0,0 +1,29 @@
+/**
+ * @package Quarkus-Testing-Showcase
+ *
+ * @file Todo serializer
+ * @copyright 2021 Christoph Kappel <christoph@unexist.dev>
+ * @version $Id$
+ *
+ * This program can be distributed under the terms of the GNU GPLv2.
+ * See the file LICENSE for details.
+ **/
+
+package dev.unexist.showcase.todo.infrastructure.serializer;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+
+public class DateSerializer extends JsonSerializer<LocalDate> {
+
+    @Override
+    public void serialize(LocalDate value, JsonGenerator gen,
+                          SerializerProvider serializers) throws IOException {
+        gen.writeString(value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+    }
+}
\ No newline at end of file