Skip to content

Allow creation of custom sub-types of NullNode, BooleanNode, MissingNode #1799

@andylowry

Description

@andylowry

The JsonNodeFactory instance always uses canonical instances for certain values of certain node types, including empty arrays, empty objects, ints from -1 to 10, booleans, maybe others.

I have a use-case where I need to parse a JSON/YAML file to a JsonNode tree and use the nodes as keys in an IdentityHashMap. The canonical instances were, naturally, causing problems.

I've created my own factory and installed it in my mapper instances, and that works great. But I can't currently avoid canonical instances of BooleanNode, NullNode and MissingNode, because none of them have a visible constructor (so I can't call the constructors, and I can't extend the types).

I don't actually have a need for non-canonical MissingNode, and my inability to manufacture non-canonical boolean and null nodes is something I can live with (that prevents an unlikely edge-case for my application from working correctly, but I can document that and leave it as is for now).

Adding public constructors to these types would make it possible for me to complete my custom factory. Making existing constructors package-visible and adding a DeserializationFeature that avoids canonical instances would probably be even better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions