Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fedelway opened this issue Feb 23, 2024 · 2 comments
Closed

Comments

@fedelway
Copy link

fedelway commented Feb 23, 2024

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.

@rlodge
Copy link
Contributor

rlodge commented Feb 29, 2024

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

@rlodge
Copy link
Contributor

rlodge commented Mar 10, 2024

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.

@rlodge rlodge closed this as completed Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants