Skip to content

Commit a8776a6

Browse files
authored
Add failing test for #279 (#317)
1 parent f71fbf2 commit a8776a6

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public WrapperWithReadTimestampsAsNanosEnabled() { }
6666
public WrapperWithReadTimestampsAsNanosEnabled(OffsetDateTime v) { value = v; }
6767
}
6868

69-
private ObjectMapper MAPPER = newMapper();
69+
private final ObjectMapper MAPPER = newMapper();
7070

7171
@Test
7272
public void testDeserializationAsFloat01WithoutTimeZone() throws Exception
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.fasterxml.jackson.datatype.jsr310.failing;
2+
3+
import java.time.OffsetDateTime;
4+
import java.time.ZoneId;
5+
import java.time.temporal.ChronoUnit;
6+
7+
import org.junit.Test;
8+
9+
import com.fasterxml.jackson.annotation.JsonFormat;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;
12+
13+
import static org.junit.Assert.assertEquals;
14+
15+
public class OffsetDateTimeDeser279Test extends ModuleTestBase
16+
{
17+
// For [modules-java8#279]
18+
static class Wrapper279 {
19+
OffsetDateTime date;
20+
21+
public Wrapper279(OffsetDateTime d) { date = d; }
22+
protected Wrapper279() { }
23+
24+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
25+
public OffsetDateTime getDate() {
26+
return date;
27+
}
28+
public void setDate(OffsetDateTime date) {
29+
this.date = date;
30+
}
31+
}
32+
33+
private ObjectMapper MAPPER = newMapper();
34+
35+
// For [modules-java8#279]
36+
@Test
37+
public void testWrapperWithPattern279() throws Exception
38+
{
39+
final OffsetDateTime date = OffsetDateTime.now(ZoneId.of("UTC"))
40+
.truncatedTo(ChronoUnit.SECONDS);
41+
final Wrapper279 input = new Wrapper279(date);
42+
final String json = MAPPER.writeValueAsString(input);
43+
44+
Wrapper279 result = MAPPER.readValue(json, Wrapper279.class);
45+
assertEquals(input.date, result.date);
46+
}
47+
}

0 commit comments

Comments
 (0)