v1.4 LocalDate support

This commit is contained in:
Shautvast 2023-06-25 15:36:22 +02:00
parent 06a15f3feb
commit b3687452f6
5 changed files with 29 additions and 6 deletions

View file

@ -5,12 +5,12 @@
<parent>
<groupId>nl.sander</groupId>
<artifactId>jsonthingy-pom</artifactId>
<version>1.4</version>
<version>1.5</version>
</parent>
<name>JsonToy-JMH</name>
<artifactId>jsonthingy-jmhtests</artifactId>
<version>1.4</version>
<version>1.5</version>
<packaging>jar</packaging>
<properties>

View file

@ -5,12 +5,12 @@
<parent>
<groupId>nl.sander</groupId>
<artifactId>jsonthingy-pom</artifactId>
<version>1.4</version>
<version>1.5</version>
</parent>
<name>JsonToy</name>
<artifactId>jsonthingy</artifactId>
<version>1.4</version>
<version>1.5</version>
<packaging>jar</packaging>
<properties>

View file

@ -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("\"");

View file

@ -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)));
}
}

View file

@ -5,7 +5,7 @@
<name>JsonToy</name>
<groupId>nl.sander</groupId>
<artifactId>jsonthingy-pom</artifactId>
<version>1.4</version>
<version>1.5</version>
<packaging>pom</packaging>
<modules>