Skip to content

Commit 0dc8b9b

Browse files
committed
Add failing test for #78
1 parent 2840b60 commit 0dc8b9b

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/YearDeserTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,16 @@ public class YearDeserTest extends ModuleTestBase
3333
private final ObjectMapper MAPPER = newMapper();
3434

3535
@Test
36-
public void testDeserialization01() throws Exception
36+
public void testDefaultDeserialization() throws Exception
3737
{
3838
Year value = MAPPER.readValue("1986", Year.class);
3939
assertEquals("The value is not correct.", Year.of(1986), value);
40-
}
41-
42-
@Test
43-
public void testDeserialization02() throws Exception
44-
{
45-
Year value = MAPPER.readValue("2013", Year.class);
40+
value = MAPPER.readValue("2013", Year.class);
4641
assertEquals("The value is not correct.", Year.of(2013), value);
4742
}
4843

4944
@Test
50-
public void testDeserializationWithTypeInfo01() throws Exception
45+
public void testDeserializationWithTypeInfo() throws Exception
5146
{
5247
ObjectMapper mapper = newMapper()
5348
.addMixIn(Temporal.class, MockObjectConfiguration.class);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2013 FasterXML.com
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the license for the specific language governing permissions and
14+
* limitations under the license.
15+
*/
16+
17+
package com.fasterxml.jackson.datatype.jsr310.failing;
18+
19+
import java.time.Year;
20+
import java.time.temporal.Temporal;
21+
22+
import com.fasterxml.jackson.annotation.JsonFormat;
23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import com.fasterxml.jackson.datatype.jsr310.MockObjectConfiguration;
25+
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;
26+
27+
import org.junit.Test;
28+
29+
import static org.junit.Assert.assertEquals;
30+
import static org.junit.Assert.assertTrue;
31+
32+
public class YearDeser78Test extends ModuleTestBase
33+
{
34+
// [module-java8#78]
35+
final static class ObjectTest {
36+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "'Y'yyyy")
37+
public Year value;
38+
39+
public ObjectTest(Year y) {
40+
value = y;
41+
}
42+
}
43+
44+
private final ObjectMapper MAPPER = newMapper();
45+
46+
// [module-java8#78]
47+
@Test
48+
public void testWithCustomFormat() throws Exception
49+
{
50+
ObjectTest input = new ObjectTest(Year.of(2018));
51+
String json = MAPPER.writeValueAsString(input);
52+
assertEquals("{\"customYear\":\"Y2018\"}", json);
53+
ObjectTest result = MAPPER.readValue(json, ObjectTest.class);
54+
assertEquals(input, result);
55+
}
56+
}

0 commit comments

Comments
 (0)