Skip to content

Declared Object in ConstructingObjectParser is ignored in case target object is already built. #34351

@bizybot

Description

@bizybot

We found a somewhat unexpected behavior of the ConstructingObjectParser.
While parsing JSON object { "role_mapping" : { "created" : "true" } }, if we declare
inner field "create" as a constructorArg along with the field "role_mapping" for which the parser is a no-op, the target object is still constructed.

static {
        PARSER.declareBoolean(constructorArg(), new ParseField("created"));
        PARSER.declareObject((a,b) -> {}, (parser, context) -> null, new ParseField("role_mapping"));
}

We continue to sub parse the object for role_mapping and once we encounter constructorArg we build the target object. The field role_mapping object is queued but later ignored.

The behaviour seems to be similar to what we do for unknown fields or optional constructor args, but
not sure about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions