Skip to content

Commit 8724ec5

Browse files
committed
Adding test (passing) for #46
1 parent 5866c5f commit 8724ec5

File tree

4 files changed

+58
-21
lines changed

4 files changed

+58
-21
lines changed

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/PolymorphicTest.java renamed to datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/DefaultTypingTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.datatype.jsr310;
1+
package com.fasterxml.jackson.datatype.jsr310.deser;
22

33
import java.time.ZoneId;
44

@@ -7,8 +7,9 @@
77
import static org.junit.Assert.assertEquals;
88

99
import com.fasterxml.jackson.databind.ObjectMapper;
10+
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;
1011

11-
public class PolymorphicTest extends ModuleTestBase
12+
public class DefaultTypingTest extends ModuleTestBase
1213
{
1314
private final ObjectMapper TYPING_MAPPER = newMapper();
1415
{

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateDeserialization.java renamed to datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalDateDeserTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.datatype.jsr310;
1+
package com.fasterxml.jackson.datatype.jsr310.deser;
22

33
import java.io.IOException;
44
import java.time.LocalDate;
@@ -16,8 +16,9 @@
1616
import com.fasterxml.jackson.databind.DeserializationFeature;
1717
import com.fasterxml.jackson.databind.ObjectReader;
1818
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
19+
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;
1920

20-
public class TestLocalDateDeserialization extends ModuleTestBase
21+
public class LocalDateDeserTest extends ModuleTestBase
2122
{
2223
private final ObjectReader READER = newMapper().readerFor(LocalDate.class);
2324

@@ -47,30 +48,30 @@ public void testDeserializationAsArrayDisabled() throws Throwable
4748
@Test
4849
public void testDeserializationAsEmptyArrayDisabled() throws Throwable
4950
{
50-
// works even without the feature enabled
51-
assertNull(read("[]"));
51+
// works even without the feature enabled
52+
assertNull(read("[]"));
5253
}
53-
54+
5455
@Test
5556
public void testDeserializationAsArrayEnabled() throws Throwable
5657
{
57-
String json="['2000-01-01']";
58-
LocalDate value= newMapper()
59-
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
60-
.readerFor(LocalDate.class).readValue(aposToQuotes(json));
61-
notNull(value);
58+
String json="['2000-01-01']";
59+
LocalDate value= newMapper()
60+
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
61+
.readerFor(LocalDate.class).readValue(aposToQuotes(json));
62+
notNull(value);
6263
expect(LocalDate.of(2000, 1, 1), value);
6364
}
6465

6566
@Test
6667
public void testDeserializationAsEmptyArrayEnabled() throws Throwable
6768
{
68-
String json="[]";
69-
LocalDate value= newMapper()
70-
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
71-
.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
72-
.readerFor(LocalDate.class).readValue(aposToQuotes(json));
73-
assertNull(value);
69+
String json="[]";
70+
LocalDate value= newMapper()
71+
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
72+
.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
73+
.readerFor(LocalDate.class).readValue(aposToQuotes(json));
74+
assertNull(value);
7475
}
7576

7677
private void expectFailure(String json) throws Throwable {

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateSerialization.java renamed to datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/ser/LocalDateSerTest.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
* limitations under the license.
1515
*/
1616

17-
package com.fasterxml.jackson.datatype.jsr310;
17+
package com.fasterxml.jackson.datatype.jsr310.ser;
1818

1919
import com.fasterxml.jackson.annotation.JsonFormat;
20+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
2021
import com.fasterxml.jackson.databind.JsonMappingException;
2122
import com.fasterxml.jackson.databind.ObjectMapper;
2223
import com.fasterxml.jackson.databind.SerializationFeature;
24+
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
25+
import com.fasterxml.jackson.datatype.jsr310.MockObjectConfiguration;
26+
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;
27+
2328
import java.time.Instant;
2429
import java.time.LocalDate;
2530
import java.time.LocalDateTime;
@@ -33,7 +38,7 @@
3338
import static org.junit.Assert.assertNotNull;
3439
import static org.junit.Assert.assertTrue;
3540

36-
public class TestLocalDateSerialization
41+
public class LocalDateSerTest
3742
extends ModuleTestBase
3843
{
3944
final static class Wrapper {
@@ -60,6 +65,19 @@ public VanillaWrapper() { }
6065
public VanillaWrapper(LocalDate v) { value = v; }
6166
}
6267

68+
// [modules-java8#46]
69+
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
70+
static class Holder46 {
71+
public LocalDate localDate;
72+
73+
public Object object;
74+
75+
public Holder46(LocalDate localDate, Object object) {
76+
this.localDate = localDate;
77+
this.object = object;
78+
}
79+
}
80+
6381
private final ObjectMapper MAPPER = newMapper();
6482

6583
@Test
@@ -263,4 +281,21 @@ public void testCustomFormatToEpochDay() throws Exception
263281
assertNotNull(date);
264282
assertEquals(LocalDate.ofEpochDay(1000), date);
265283
}
284+
285+
// [modules-java8#46]
286+
public void testPolymorphicSerialization() throws Exception
287+
{
288+
ObjectMapper mapper = newMapper();
289+
StdTypeResolverBuilder typeResolverBuilder =
290+
new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.NON_FINAL)
291+
.init(JsonTypeInfo.Id.CLASS, null)
292+
.inclusion(JsonTypeInfo.As.WRAPPER_OBJECT);
293+
294+
mapper = new ObjectMapper();
295+
mapper.setDefaultTyping(typeResolverBuilder);
296+
final LocalDate localDate = LocalDate.of(2017, 12, 5);
297+
String dateHolderStr = mapper.writeValueAsString(new Holder46(localDate, localDate));
298+
assertEquals(aposToQuotes("{\"localDate\":[2017,12,5],\"object\":{\"java.time.LocalDate\":[2017,12,5]}}"),
299+
dateHolderStr);
300+
}
266301
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>com.fasterxml.jackson</groupId>
55
<artifactId>jackson-base</artifactId>
6-
<version>2.9.2</version>
6+
<version>2.9.3-SNAPSHOT</version>
77
</parent>
88
<groupId>com.fasterxml.jackson.module</groupId>
99
<artifactId>jackson-modules-java8</artifactId>

0 commit comments

Comments
 (0)