
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Importance of the JsonPatch interface in Java?
The JsonPatch interface is a format for storing a sequence of operations that can be applied to the target JSON structure. There are few operations like add, remove, replace, copy, move and test can be stored in JsonPath and operated on JSON structure. The JsonPatchBuilder interface can be used for constructing a JSON patch using the Json.createPatchBuilder().
JSON file
Example
import java.io.*; import javax.json.Json; import javax.json.JsonPatch; import javax.json.JsonPatchBuilder; import javax.json.JsonReader; import javax.json.JsonStructure; public class JsonPatchTest { public static void main(String[] args) throws Exception { JsonPatchBuilder jsonPatchBuilder = Json.createPatchBuilder(); JsonPatch jsonPatch = jsonPatchBuilder.add("/postalCode", "500072").remove("/age").build(); JsonReader reader = Json.createReader(new FileReader("simple.json")); JsonStructure jsonStructure1 = reader.read(); JsonStructure jsonStructure2 = jsonPatch.apply(jsonStructure1); System.out.println(jsonStructure2); reader.close(); } }
Output
{"firstName":"Raja","lastName":"Ramesh","streetAddress":"Madhapur","city":"Hyderabad","state":"Telangana","phoneNumbers":[{"Mobile":"9959984000"},{"Home":"7702144400"}],"postalCode":"500072"}
- Related Articles
- What is the importance of a FocusListener interface in Java?
- Importance of Predicate interface in lambda expression in Java?
- What is the importance of the ProcessHandle interface in Java 9?
- What is the importance of a WindowListener interface in Java?\n
- Interface in Java
- Importance of HashSet in Java
- Importance of the Jackson @JsonInclude annotation in Java?
- What is the importance of "Java.lang.Class" in Java?
- Explain the importance of import keyword in java?
- Importance of the parseBoolean() method in Java?\n
- Importance of the getCause() method in Java?\n
- What is the importance of OverlayLayout in Java?
- Importance of the Collectors.filtering() method in Java 9?
- Nested interface in Java
- Deque interface in Java

Advertisements