Skip to content

4 test failures for master due to default change (see https://github.com/FasterXML/jackson-databind/issues/3406) #701

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

Closed
cowtowncoder opened this issue Jan 30, 2025 · 6 comments
Assignees

Comments

@cowtowncoder
Copy link
Member

So, looks like some tests need changes now that DeserializationFeature.FAIL_ON_TRAILING_TOKENS is enabled by default.
Databind had a few, mostly bad json in test (trailing quotes or duplicated ']/}at the end). Can also just ensure default for setting isfalse` if that makes more sense.

@pjfanning
Copy link
Member

I'll look into the issue. At least 1 of the failing tests serializes an object instance with Jackson and tries to deserialize the resultant json with Jackson as a round trip. Could be an edge case where empty json is created.

@pjfanning
Copy link
Member

I can confirm one test seralizes an object with no fields and the resultant json is {}.
The test then fails when we try to deserialize {}. @cowtowncoder is this possibly a bug in Jackson-Databind? Isn't {} valid json? Is it not a valid representation of empty data for a class with no fields?

@pjfanning
Copy link
Member

I have a similar test in the same test class that serializes an object instance as {"field":"bar"}. Jackson fails to parse this now when I try to get Jackson to deserialize this json.

This error looks like:

Trailing token (of type PROPERTY_NAME) found after value (bound as `tools.jackson.module.scala.deser.CaseObjectDeserializerTest$Foo$`): not allowed as per `DeserializationFeature.FAIL_ON_TRAILING_TOKENS`
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #UNKNOWN]
tools.jackson.databind.exc.MismatchedInputException: Trailing token (of type PROPERTY_NAME) found after value (bound as `tools.jackson.module.scala.deser.CaseObjectDeserializerTest$Foo$`): not allowed as per `DeserializationFeature.FAIL_ON_TRAILING_TOKENS`
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #UNKNOWN]
	at tools.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:56)
	at tools.jackson.databind.DeserializationContext.reportTrailingTokens(DeserializationContext.java:1829)
	at tools.jackson.databind.ObjectMapper._verifyNoTrailingTokens(ObjectMapper.java:2687)
	at tools.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2581)
	at tools.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1570)
	at tools.jackson.module.scala.deser.CaseObjectDeserializerTest.$anonfun$new$2(CaseObjectDeserializerTest.scala:36)

@cowtowncoder
Copy link
Member Author

{} is definitely legal. But most commonly these seem to be from either actual extra fluff -- I noticed that single opening quote can be detected and reported as likely trailing JsonToken.VALUE_STRING -- or Deserializer actually not consuming content.

In case of PROPERTY_NAME it could specifically happen.
So maybe digging bit into CaseObjectDeserializer would work -- is there any chance of it leaving content unread?

In case of {"field":"bar"} that'd mean that deserializer simply returns something without consuming "field":"bar"} part (opening { has been consumed).

@pjfanning
Copy link
Member

Reasonable point. The ScalaObjectDeserializer was not consuming the tokens. e755834 fixes the tests but sort of shows that deserializing Scala Objects (singleton class instances in Java) is a bit of an edge case and the code in ScalaObjectDeserializer is just not right. I'll see if it can be improved. The change I've added gets around the immediate issue. I will backport it to branch 2.19.

@cowtowncoder
Copy link
Member Author

Excellent! We did find a few test problems in jackson-databind, was useful. But no actual bugs (as far as I remember).

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

No branches or pull requests

2 participants