-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #490: regression in Double/Float conversion for "untyped" deseria…
…lization (#492)
- Loading branch information
1 parent
1efa12b
commit 4d4d141
Showing
4 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
ion/src/test/java/com/fasterxml/jackson/dataformat/ion/DatabindNumberRoundtrip490Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.fasterxml.jackson.dataformat.ion; | ||
|
||
import java.util.*; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
// for [dataformats-binary#490] | ||
public class DatabindNumberRoundtrip490Test | ||
{ | ||
private final IonObjectMapper BINARY_MAPPER = IonObjectMapper.builderForBinaryWriters() | ||
.build(); | ||
private final IonObjectMapper TEXT_MAPPER = IonObjectMapper.builderForTextualWriters() | ||
.build(); | ||
|
||
@Test | ||
public void testBinaryFloats() throws Exception { | ||
_floatRoundtrip(BINARY_MAPPER); | ||
} | ||
|
||
@Test | ||
public void testBinaryIntegers() throws Exception { | ||
_integerRoundtrip490(BINARY_MAPPER); | ||
} | ||
|
||
@Test | ||
public void testTextualFloats() throws Exception { | ||
_floatRoundtrip(TEXT_MAPPER); | ||
} | ||
|
||
@Test | ||
public void testTextualIntegers() throws Exception { | ||
_integerRoundtrip490(TEXT_MAPPER); | ||
} | ||
|
||
private void _floatRoundtrip(ObjectMapper mapper) throws Exception | ||
{ | ||
final double d = 42.25d; | ||
final float f = 42.75f; | ||
|
||
_roundtrip490(mapper, d, d); | ||
|
||
// Ion oddity: "float"s get upgraded to "double"s, so... | ||
_roundtrip490(mapper, f, (double) f); | ||
} | ||
|
||
private void _integerRoundtrip490(ObjectMapper mapper) throws Exception | ||
{ | ||
_roundtrip490(mapper, Integer.MAX_VALUE, Integer.MAX_VALUE); | ||
_roundtrip490(mapper, Long.MAX_VALUE, Long.MAX_VALUE); | ||
} | ||
|
||
private void _roundtrip490(ObjectMapper mapper, | ||
Object input, Object result) | ||
throws Exception | ||
{ | ||
byte[] serialized = mapper.writeValueAsBytes(Collections.singletonMap("k", input)); | ||
|
||
Map<?,?> deserialized = mapper.readValue(serialized, Map.class); | ||
assertEquals(result, deserialized.get("k")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters