Skip to content

Generated ObjectId is generating exceptions that are being written to stderr #243

@fedelway

Description

@fedelway

Hi,

When using @JsonCreator based classes and @ObjectId there is an UnsupportedOperationException when trying to set the returned ObjectId.

This is because of JacksonCodec:120 :

beanPropertyDefinition.getMutator().setValue(

getMutator returns by default the constructor parameter, and jackson cannot mutate (setValue) on a constructor parameter, so the exception is raised.

A simple fix would be to use the alternative method getNonConstructorMutator() in which we can get the Setter and thus, change the value without raising an exception.

In my case I'm not entirely interested in mutating the inserted POJO, but the main problem I have is the exception is constantly being written to stderr because of the line 126:

            try {
                if (bsonObjectId != null) {
                    beanPropertyDefinition.getMutator().setValue(
                        t,
                        extractIdValue(bsonObjectId, beanPropertyDefinition.getRawPrimaryType())
                    );
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

Everytime the exception is raised is written to stderr and there is no logger support to disable this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions