Skip to content

reuse-objectmapper-defaultjsonparser #3372

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thachlp
Copy link
Contributor

@thachlp thachlp commented Jul 24, 2025

Refactor DefaultJsonParser to use a single static ObjectMapper instance instead of creating new instances for each method call, improving performance and memory usage.
Issue #3370

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You applied code formatting rules using the mvn formatter:format target. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Refactor DefaultJsonParser to use a single static ObjectMapper instance instead of creating new instances for each method call, improving performance and memory usage.
@cjdxhjj
Copy link

cjdxhjj commented Jul 25, 2025

Can this be specified through options? For example, specifying a DefaultJsonParser instance, allowing replacement with different implementations, and permitting the passing of an ObjectMapper instance—such as one from a configured Spring container that has modules installed or some configurations applied.

@cjdxhjj
Copy link

cjdxhjj commented Jul 25, 2025

@thachlp If no ObjectMapper is specified in DefaultJsonParser, a new one will be created; otherwise, the specified instance will be used.

@tishun
Copy link
Collaborator

tishun commented Jul 29, 2025

@cjdxhjj let me repeat what you suggested to make sure we are on the same page: you'd like to be able to pass an existing instance of the ObjectMapper so that we don't have to create one at all, if it is already used by the client app?

@thachlp I think it makes sense to be able to have the following logic:

  • have two constructors in the DefaultJsonParser - one with 1 parameter (the ObjectMapper) and one without any parameters
  • the constructor with no parameters is used, as now, to create one instance of the ObjectMapper once the parser is created
  • the constructor with the parameter is used to reuse an existing instance of the ObjectMapper
  • if the application already has an instance of the ObjectMapper it would manually change provide a new instance of the DefaultJsonParser with an ObjectMapper

Does that make sense?

@cjdxhjj
Copy link

cjdxhjj commented Jul 30, 2025

@thachlp yes, that right.In my case, some custom serialization has been implemented. For example, Kotlin, Scala, and Long types are serialized into strings to support the frontend, etc. Therefore, using that existing instance might be more appropriate than creating a new one. Of course, users are completely free to customize what kind of instance to create.

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

Successfully merging this pull request may close these issues.

3 participants