diff --git a/jmh/pom.xml b/jmh/pom.xml index b01b42c..b7d6a1b 100644 --- a/jmh/pom.xml +++ b/jmh/pom.xml @@ -5,12 +5,12 @@ nl.sander jsonthingy-pom - 1.4 + 1.5 JsonToy-JMH jsonthingy-jmhtests - 1.4 + 1.5 jar diff --git a/lib/pom.xml b/lib/pom.xml index 36476bf..73c5d71 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -5,12 +5,12 @@ nl.sander jsonthingy-pom - 1.4 + 1.5 JsonToy jsonthingy - 1.4 + 1.5 jar diff --git a/lib/src/main/java/nl/sanderhautvast/json/ser/Mapper.java b/lib/src/main/java/nl/sanderhautvast/json/ser/Mapper.java index 1391fe3..59456f4 100644 --- a/lib/src/main/java/nl/sanderhautvast/json/ser/Mapper.java +++ b/lib/src/main/java/nl/sanderhautvast/json/ser/Mapper.java @@ -7,6 +7,8 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -80,7 +82,7 @@ public class Mapper { b.append("\""); Mapper.escape(b, (Character) value); b.append("\""); - } else if (type == UUID.class || type.isEnum()) { + } else if (type == UUID.class || type == LocalDate.class || type == LocalDateTime.class || type.isEnum()) { b.append("\""); b.append(value.toString()); b.append("\""); diff --git a/lib/src/test/java/nl/sanderhautvast/json/ser/LocalDateTest.java b/lib/src/test/java/nl/sanderhautvast/json/ser/LocalDateTest.java new file mode 100644 index 0000000..fb26523 --- /dev/null +++ b/lib/src/test/java/nl/sanderhautvast/json/ser/LocalDateTest.java @@ -0,0 +1,21 @@ +package nl.sanderhautvast.json.ser; + +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class LocalDateTest { + + @Test + void testLocalDate() { + assertEquals("\"2023-10-11\"", Mapper.json(LocalDate.of(2023, 10, 11))); + } + + @Test + void testLocalDateTime() { + assertEquals("\"2023-10-11T13:15:27\"", Mapper.json(LocalDateTime.of(2023, 10, 11,13,15,27))); + } +} diff --git a/pom.xml b/pom.xml index 8dd4ffd..0d7df72 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ JsonToy nl.sander jsonthingy-pom - 1.4 + 1.5 pom