Comments (7)
Thank you so much for your help!
from jackson-dataformats-binary.
Quick question: is this
Assertions.assertEquals(42D, deserialized.get("float")); // FAILED with Jackson 2.17.0
Assertions.assertEquals(42D, deserialized.get("double")); // FAILED with Jackson 2.17.0
intentional? Shouldn't first one compare to 42F
not 42D
?
And yes, type of numbers should be retained: numbers written as float
s should be decoded as float
s (unless target type is double
in which case coercion is to occur), and same for double
.
As to the root cause, it looks like a regression: probably due to changes intended (ironically enough) retain type across those backends capable of distinguishing difference (textual formats like JSON cannot, binary formats like Ion typically do).
I'll see if I find time to create a unit test and see what is happening
EDIT: no, I get it now; test is as intended due to "Double-ness" of Ion API.
from jackson-dataformats-binary.
Ohhhh. Now I remember: one oddity of IonParser
is that underlying data format reader (IonReader
) does not appear to indicate 32-bit float
type at all -- instead IonType.FLOAT
refers to 64-bit double
(double precision IEEE-754). As such, true type cannot be -- it seems -- preserved.
Similarly, IonWriter.writeFloat(double)
does not have float
-taking counterpart... so I guess Ion only does double
.
At any rate, precision should never be lost so getting float
back for something written as double
seems wrong regardless.
from jackson-dataformats-binary.
Ok. Yeah, I was right to be suspicious -- looks like this from 2.17 branch IonParser
:
@Override // since 2.17
public NumberTypeFP getNumberTypeFP() throws IOException
{
if (_currToken == JsonToken.VALUE_NUMBER_FLOAT) {
final IonType type = _reader.getType();
if (type == IonType.FLOAT) {
// 06-Jan-2024, tatu: Existing code maps Ion `FLOAT` into Java
// `float`. But code in `IonReader` suggests `Double` might
// be more accurate mapping... odd.
return NumberTypeFP.FLOAT32;
}
if (type == IonType.DECIMAL) {
// 06-Jan-2024, tatu: Seems like `DECIMAL` is expected to map
// to `BigDecimal`, as per existing code so:
return NumberTypeFP.BIG_DECIMAL;
}
}
return NumberTypeFP.UNKNOWN;
}
so I think that's what should be changed. But I'll need more time to investigate this...
from jackson-dataformats-binary.
Ugh. And documentation is both precise and slightly confusing:
https://amazon-ion.github.io/ion-docs/docs/float.html
claims that both 32- and 64-bit FP values are supported.
yet then goes to say...
" In the data model, all floating point values are treated as though they are binary64 "
Hmmmh.
Ok.
from jackson-dataformats-binary.
Fixed in 2.17 branch for upcoming 2.17.1 release
from jackson-dataformats-binary.
FWTW, Jackson 2.17.1 was just released, with ~20 fixes this included:
https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.17.1
from jackson-dataformats-binary.
Related Issues (20)
- `IndexOutOfBoundsException` in `JacksonAvroParserImpl` for invalid input
- `IndexOutOfBoundsException` in `CBORParser` for invalid input
- Unexpected NullPointerException in `CBORParser`
- Unexpected `NullPointerException` in `ProtobufParser.currentName()`
- `ProtobufParser.currentName()` returns wrong value at root level
- Unexpected `ArrayIndexOutOfBoundsException` in `CBORParser` for corrupt String value
- IonReader.newBytes() throwing `NegativeArraySizeException` HOT 1
- `IonReader` throws `AssertionError` for Timestamp value HOT 1
- `IonReader.next()` throws `ArrayIndexOutOfBoundsException` for some corrupt content HOT 4
- Support for `StreamReadConstraints.maxNameLength` validation for CBOR, Smile backends
- protobuf LocalDateTime UnsupportedOperationException HOT 1
- Upgrade `ion-java` to latest (1.11.4)
- Upgrade `ion-java` to latest (1.11.7)
- ION - MappingIterator skip the first line
- Avro Schema generation: allow mapping Java Enum properties to Avro String values HOT 7
- Issue in Smile shared string values due to avoiding 0xFE and 0xFF HOT 6
- Failed copy(): `IonValueMapper` does not override copy() HOT 1
- [AVRO] 2 fields in schema for single property when getter and setter contain property name in capitals. HOT 3
- Upgrade `ion-java` dependency to 1.11.8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-dataformats-binary.