Skip to content

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

Closed

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.

Activity

  1. rlodge commented on Feb 29, 2024

    @rlodge
    Contributor

    Published a 4.11.0-SNAPSHOT version that utilizes slf4j to log these instead.

  2. rlodge commented on Mar 10, 2024

    @rlodge
    Contributor

    I released 4.11.0, with this addition of SLF4J. If you would like to provide a fix to the underlying issue along with tests via PR, please feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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