Search in sources :

Example 26 with JsonPatch

use of org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch in project dhis2-core by dhis2.

the class RemoveOperationTest method testRemovePropertyFromMap.

@Test
void testRemovePropertyFromMap() throws JsonProcessingException, JsonPatchException {
    JsonPatch patch = jsonMapper.readValue("[" + "{\"op\": \"remove\", \"path\": \"/props/id\"}" + "]", JsonPatch.class);
    assertNotNull(patch);
    Map<String, String> map = new HashMap<>();
    map.put("id", "123");
    ObjectNode root = jsonMapper.createObjectNode();
    root.set("props", jsonMapper.valueToTree(map));
    assertTrue(root.has("props"));
    assertTrue(root.get("props").has("id"));
    root = (ObjectNode) patch.apply(root);
    assertTrue(root.has("props"));
    assertFalse(root.get("props").has("id"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) JsonPatch(org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch) Test(org.junit.jupiter.api.Test)

Aggregations

JsonPatch (org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch)26 Test (org.junit.jupiter.api.Test)20 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 JsonPatchException (org.hisp.dhis.commons.jackson.jsonpatch.JsonPatchException)5 List (java.util.List)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 Schema (org.hisp.dhis.schema.Schema)4 SchemaService (org.hisp.dhis.schema.SchemaService)4 Service (org.springframework.stereotype.Service)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 AllArgsConstructor (lombok.AllArgsConstructor)3 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 ErrorCode (org.hisp.dhis.feedback.ErrorCode)3 ErrorReport (org.hisp.dhis.feedback.ErrorReport)3 ObjectReport (org.hisp.dhis.feedback.ObjectReport)3 TypeReport (org.hisp.dhis.feedback.TypeReport)3