Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add big decimal tests #565

Merged
merged 4 commits into from
Mar 20, 2025
Merged

add big decimal tests #565

merged 4 commits into from
Mar 20, 2025

Conversation

pjfanning
Copy link
Member

Currently broken. CBOR and Smile tests based on FasterXML/jackson-databind#4917

These are round trip tests and I would have expected that the binary data that is serialized to be ok to read back (deserialized).

The tests fail with exceptions like:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.math.BigDecimal` from Object value (token `JsonToken.FIELD_NAME`)
 at [Source: (byte[])[46 bytes]; byte offset: #16] (through reference chain: com.fasterxml.jackson.dataformat.cbor.mapper.NumberBeanTest$DeserializationIssue4917["decimalHolder"])

	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1794)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1568)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1515)
	at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$BigDecimalDeserializer.deserialize(NumberDeserializers.java:1034)
	at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$BigDecimalDeserializer.deserialize(NumberDeserializers.java:988)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1492)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:348)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)

@pjfanning
Copy link
Member Author

@cowtowncoder I don't a great deal about CBOR and Smile but I thought these scenarios should have worked without too much stress. Would you have a look?

@cowtowncoder
Copy link
Member

cowtowncoder commented Feb 11, 2025

That looks very odd -- tests do indeed look simple. I'll need to dig deeper later on.

One thing that might help is to try to create alternate tests that just use streaming API, trying to replicate what databind does. There must be some incomplete state update somewhere.
Interesting that both CBOR and Smile have (it seems) same issue.

EDIT: I was too quick -- test itself has an issue, see below.

@cowtowncoder
Copy link
Member

@pjfanning Ah. Tests are not valid -- it's not round-tripping: Serialization with wrapper is as

{
  "decimalHolder" : {
    "value" : 1E+2
  },
  "number" : 50.0
}

but due to

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
        static DecimalHolder4917 of(BigDecimal value) {
            return new DecimalHolder4917(value);
        }

deserializer instead expects structure like:

{
  "decimalHolder" :  1E+2
  "number" : 50.0
}

so it's DELEGATING vs actually PROPERTIES style serialization.

Same problem would happen with JSON and other formats.

@cowtowncoder
Copy link
Member

@pjfanning I fixed the tests by adding @JsonValue to make serialization work the way deserialization expects.

@cowtowncoder cowtowncoder merged commit a9cc726 into FasterXML:2.19 Mar 20, 2025
4 checks passed
@pjfanning pjfanning deleted the tests branch March 20, 2025 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants