Best way to update object inside array

Hi, I'm trying to update an object inside an
{
...
arrayKey: [{
key1: value1,
key2: value2
}
]
...
}

The objective is to change the value of key1. The only way I could find to do it, is to replace the entire object with the following:

   String objectValue = new ObjectMapper().valueToTree(fieldValue.get(0)).toString();
        XContentParser parser = JsonXContent.jsonXContent
                .createParser(NamedXContentRegistry.EMPTY,objectValue);
        contentBuilder.startArray(fieldName);
        contentBuilder.copyCurrentStructure(parser);
        contentBuilder.endArray();

Is there a better way? Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.