Package com.github.fge.jsonpatch

Examples of com.github.fge.jsonpatch.JsonPatch


        // Use the Jackson 2.x classes to convert both the incoming patch
        // and the current state of the object into a JsonNode / JsonPatch
        ObjectMapper mapper = new ObjectMapper();
        JsonNode serverState = mapper.readValue(baos.toByteArray(), JsonNode.class);
        JsonNode patchAsNode = mapper.readValue(readerInterceptorContext.getInputStream(), JsonNode.class);
        JsonPatch patch = JsonPatch.fromJson(patchAsNode);

        try {
            // Apply the patch
            JsonNode result = patch.apply(serverState);

            // Stream the result & modify the stream on the readerInterceptor
            ByteArrayOutputStream resultAsByteArray = new ByteArrayOutputStream();
            mapper.writeValue(resultAsByteArray, result);
            readerInterceptorContext.setInputStream(new ByteArrayInputStream(resultAsByteArray.toByteArray()));
View Full Code Here


        JsonNode jsonNode = convertToJsonNode(json);
        for (JsonNode operation : patch) {
            try {
                final ArrayNode nodes = JsonNodeFactory.instance.arrayNode();
                nodes.add(operation);
                JsonPatch patchOperation = JsonPatch.fromJson(nodes);
                jsonNode = patchOperation.apply(jsonNode);
            } catch (JsonPatchException e) {
                logger.log(Level.FINEST, "ignore field not found");
            }
        }
        return jsonNode;
View Full Code Here

TOP

Related Classes of com.github.fge.jsonpatch.JsonPatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.