JSON-P 1.1

JSON processing APIs is updated and aligned with Java 8, and provides Stream support for JSON reader.

Let's create an example to demonstrate it.

public class Person implements Serializable {

    private String name;
    private LocalDate birthDate;
    private List<PhoneNumber> phoneNumbers = new ArrayList<>();

    // setters and getters
}

public class PhoneNumber implements Serializable {

    public static enum Type {
        HOME, OFFICE;
    }

    private Type type;
    private String number;

    // setters and getters
}

Assume we have a contact list in JSON file, we will read it and convert into Person.

Convert JsonArray to Stream via stream method.

JSON-P 1.1 also added JSON Pointerarrow-up-right, JSON Patcharrow-up-right, JSON Merge Patcharrow-up-right support.

An example of using JSON Pointer to query JSON node.

An example of using JSON Patch to update some JSON nodes.

They are very useful to patch the existing entity when add HTTP Patch method support in RESTful APIs, we will demonstrate this later in JAX-RS.

Grab the source codesarrow-up-right from my GitHub account, and have a try.

Last updated