Skip to content

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.
Closes #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.

Copy link
Contributor Author

@thachlp thachlp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cjdxhjj @tishun
Please help review the change 🙇

Copy link

@cjdxhjj cjdxhjj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGBT

@tishun tishun added this to the 6.8.0.RELEASE milestone Aug 5, 2025
Copy link
Collaborator

@tishun tishun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@tishun tishun merged commit 5794560 into redis:main Aug 7, 2025
8 checks passed
svc-squareup-copybara pushed a commit to cashapp/misk that referenced this pull request Aug 8, 2025
| Package | Type | Package file | Manager | Update | Change |
|---|---|---|---|---|---|
| [io.lettuce:lettuce-core](https://github.com/redis/lettuce) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`6.7.1.RELEASE` -> `6.8.0.RELEASE` |
| [com.squareup.wire](https://github.com/square/wire) | plugin |
misk/gradle/libs.versions.toml | gradle | patch | `5.3.7` -> `5.3.8` |
| [com.squareup.wire:wire-schema](https://github.com/square/wire) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.3.7`
-> `5.3.8` |
| [com.squareup.wire:wire-runtime](https://github.com/square/wire) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.3.7`
-> `5.3.8` |
| [com.squareup.wire:wire-reflector](https://github.com/square/wire) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.3.7`
-> `5.3.8` |
| [com.squareup.wire:wire-moshi-adapter](https://github.com/square/wire)
| dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`5.3.7` -> `5.3.8` |
| [com.squareup.wire:wire-grpc-client](https://github.com/square/wire) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.3.7`
-> `5.3.8` |
| [com.squareup.wire:wire-bom](https://github.com/square/wire) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch | `5.3.7`
-> `5.3.8` |

---

### Release Notes

<details>
<summary>redis/lettuce (io.lettuce:lettuce-core)</summary>

###
[`v6.8.0.RELEASE`](https://github.com/redis/lettuce/releases/tag/6.8.0.RELEASE)

[Compare
Source](redis/lettuce@6.7.1.RELEASE...6.8.0.RELEASE)

The Lettuce team is pleased to announce the Lettuce 6.8.0 minor release!

This release provides support for the newly introduced [Redis Query
Engine
support](https://redis.github.io/lettuce/user-guide/redis-search/) which
was is part of Redis 8.0 and previously - as part of RedisStack. The new
operators (`DIFF`, `DIFF1`, `ANDOR` and `ONE`) for the `BITOP` command
are also available. The team has worked on extending the contract of the
`XADD` and `XTRIM ` commands to support trimming policy, and also
introduced the new `XDELEX` and `XACKDEL` commands.

Lettuce 6.8.0 supports Redis 2.6+ up to Redis 8.x. In terms of Java
runtime, Lettuce requires at least Java 8 and
works with Java 24. The driver is tested against Redis 8.2, Redis 8.0,
Redis 7.4 and Redis 7.2.

Find the full changelog at the end of this document.
Thanks to all contributors who made Lettuce 6.8.0.RELEASE possible.

📗 Links
Reference documentation:
https://lettuce.io/core/6.8.0.RELEASE/reference/
Javadoc: https://lettuce.io/core/6.8.0.RELEASE/api/

⭐ New Features
Introduce RediSearch by [@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3375
Add support for new operations of BITOP command in Redis Community
Edition 8.2 by [@&#8203;atakavci](https://github.com/atakavci) in
redis/lettuce#3334
Add support for 8.2 stream commands by
[@&#8203;uglide](https://github.com/uglide) in
redis/lettuce#3374

🐞 Bug Fixes
NoClassDefFoundError in Lettuce 6.7.0
[#&#8203;3317](redis/lettuce#3317) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3318

💡 Other
The instance of the `ObjectMapper` can now be reused in the
`DefaultJsonParser` by [@&#8203;thachlp](https://github.com/thachlp) in
redis/lettuce#3372
Added basic connection interruption tests by
[@&#8203;uglide](https://github.com/uglide) in
redis/lettuce#3292
DOC-4758 async JSON doc examples by
[@&#8203;andy-stark-redis](https://github.com/andy-stark-redis) in
redis/lettuce#3335
Fixed SocketOptions.Builder validation messages by
[@&#8203;hubertchylik](https://github.com/hubertchylik) in
redis/lettuce#3366
Refactor tests for clarity and maintainability by
[@&#8203;Rian-Ismael](https://github.com/Rian-Ismael) in
redis/lettuce#3363
Provide support for the SVS-VMANA index
([#&#8203;3385](redis/lettuce#3385)) by
[@&#8203;tishun](https://github.com/tishun) in
redis/lettuce#3386

❤️ New Contributors## New Contributors

- [@&#8203;hubertchylik](https://github.com/hubertchylik) made their
first contribution in redis/lettuce#3366

**Full Changelog**:
redis/lettuce@6.7.0.RELEASE...6.8.0.RELEASE

</details>

<details>
<summary>square/wire (com.squareup.wire)</summary>

###
[`v5.3.8`](https://github.com/square/wire/blob/HEAD/CHANGELOG.md#Version-538)

[Compare Source](square/wire@5.3.7...5.3.8)

*2025-08-08*

##### Swift

- Fix edge case for oneof field named `self`
([#&#8203;3360](square/wire#3360) by
\[Dimitris Koutsogiorgas]\[dnkoutso])

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am
every weekday" in timezone Australia/Melbourne, Automerge - At any time
(no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Never, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://github.com/renovatebot/renovate).

GitOrigin-RevId: f26d0f3a5bf8e0f695433640efc9d6e93850ab60
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.

Avoid creating a new instance of the ObjectMapper
3 participants