Skip to content

Avoid creating a new instance of the ObjectMapper ctd. #3412

@brushmate

Description

@brushmate

Bug Report

Current Behavior

This follows up on #3370, which got fixed in #3372. While the ObjectMapper is now reused for parsing, a new instance is still created inside DelegateJsonValue#toObject every time it is called.

Input Code

Input Code
@Override
public <T> T toObject(Class<T> type) {
    ObjectMapper mapper = new ObjectMapper();
    try {
        return mapper.treeToValue(node, type);
    } catch (IllegalArgumentException | JsonProcessingException e) {
        throw new RedisJsonException("Unable to map the provided JsonValue to " + type.getName(), e);
    }
}

Expected behavior/code

Reduce the amount of new objects being created when working with JSON.

Environment

  • Lettuce version(s): 6.8.0.RELEASE and up
  • Redis version: any

Possible Solution

Pass the ObjectMapper configured on the DefaultJsonParser to DelegateJsonValue and its subclasses.

Additional context

N/A

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