Skip to content

Commit 371cf93

Browse files
committed
Add failing test for #307
1 parent a8776a6 commit 371cf93

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.fasterxml.jackson.datatype.jsr310.failing;
2+
3+
import java.time.Instant;
4+
5+
import org.junit.Test;
6+
7+
import com.fasterxml.jackson.databind.JsonNode;
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
// [modules-java8#307]: Loss of precision via JsonNode for BigDecimal-valued
14+
// things (like Instant)
15+
public class InstanceViaBigDecimal307Test extends ModuleTestBase
16+
{
17+
static class Wrapper307 {
18+
public Instant value;
19+
20+
public Wrapper307(Instant v) { value = v; }
21+
protected Wrapper307() { }
22+
}
23+
24+
private final Instant ISSUED_AT = Instant.ofEpochSecond(1234567890).plusNanos(123456789);
25+
26+
private ObjectMapper MAPPER = newMapper();
27+
28+
@Test
29+
public void instantViaReadValue() throws Exception {
30+
String serialized = MAPPER.writeValueAsString(new Wrapper307(ISSUED_AT));
31+
Wrapper307 deserialized = MAPPER.readValue(serialized, Wrapper307.class);
32+
assertEquals(ISSUED_AT, deserialized.value);
33+
}
34+
35+
@Test
36+
public void instantViaReadTree() throws Exception {
37+
String serialized = MAPPER.writeValueAsString(new Wrapper307(ISSUED_AT));
38+
JsonNode tree = MAPPER.readTree(serialized);
39+
Wrapper307 deserialized = MAPPER.treeToValue(tree, Wrapper307.class);
40+
assertEquals(ISSUED_AT, deserialized.value);
41+
}
42+
}

0 commit comments

Comments
 (0)