Skip to content

JsonParserSequence read methods no longer use Parsers beyond the first #1616

@stefnoten-aca

Description

@stefnoten-aca

The read methods on JsonParserSequence previously correctly used all parsers in the sequence, however after upgrading to Jackson 3.x they only use the first one. This caused corrupt parsing in our application, dropping parts of the input json. We had a custom deserializer using the same mechanism as AsPropertyTypeDeserializer (which scans ahead for an @type property, then deserializing with a JsonParserSequence of a TokenBuffer and the actual parser).

Cause

Jackson 2.x - inherited from JsonParser superclass:

public <T extends TreeNode> T readValueAsTree() throws IOException {
    return (T) _codec().readTree(this); // passing this causes all Parsers in the sequence to be used
}

Jackson 3.x - overridden by JsonParserDelegate superclass in 8ee7d0f, becoming incorrect for JsonParserSequence:

public <T extends TreeNode> T readValueAsTree() throws IOException {
    return delegate.readValueAsTree(); // delegate is set to parsers[0] for JsonParserSequence
}

Workaround

Instead of parser.readValueAsTree() (or other read methods), use context.readTree(parser)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions