Skip to content

Avoid creating a new instance of the ObjectMapper #3370

@tishun

Description

@tishun

Bug Report

Current Behavior

The ObjectMapper is created inside the parse method every time it is called. This is not optimal.
There are multiple places in the code where we create a new mapper, instead of creating it once and reusing it.

Input Code

Input Code
    @Override
    public JsonValue fromObject(Object object) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            JsonNode root = objectMapper.valueToTree(object);
            return DelegateJsonValue.wrap(root);
        } catch (IllegalArgumentException e) {
            throw new RedisJsonException("Failed to process the provided object as JSON", e);
        }
    }

Expected behavior/code

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

Environment

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

Possible Solution

N/A

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions