Building RESTful Web Services with Java EE 8 by mario-leander Reimer
Author:mario-leander Reimer
Language: eng
Format: epub
Tags: COM000000 - COMPUTERS / General, COM082000 - COMPUTERS / Bioinformatics, COM006000 - COMPUTERS / Buyer's Guides
Publisher: Packt Publishing
Published: 2018-07-31T08:18:29+00:00
Flexible JSON processing with JSON-P
In this section, we're going to take a look at using JSON-P builders to construct JSON arrays and objects. We'll see how you can use JSON-P in REST resources for marshalling and unmarshalling data, how to use JSON Pointers to access JSON structures, and have a closer look at JSON Patch and JSON Diff to modify JSON structures. We will also be using the @PATCH annotation and the application/json-patch+json content type to apply patches in our REST resources, so there's lots of content ahead.
Let's get started. As usual, we prepare a small REST resource as a template to start. The first thing we do is create arrays for JSON and JSON objects using the associated builders, so let's do that:
public void testJsonBuilder() {
JsonArray values = Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("aString", "Hello Json-P 1")
.add("aInteger", 42)
.add("aBoolean", false)
.add("aNullValue", JsonValue.NULL)
.build())
Here, we're using the createArrayBuilder to create an array builder, and we're using the add method to add JSON objects. Here, you can use Json.createObjectBuilder to obtain an object builder. On this object builder, we then call different add methods to add a string, an integer, a Boolean, or maybe a null value using the special JsonValue. That's all there is to it. Using these two builders, you can create complex JSON structures quite easily.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sapiens: A Brief History of Humankind by Yuval Noah Harari(14344)
The Tidewater Tales by John Barth(12639)
Mastermind: How to Think Like Sherlock Holmes by Maria Konnikova(7304)
Do No Harm Stories of Life, Death and Brain Surgery by Henry Marsh(6922)
The Thirst by Nesbo Jo(6906)
Why We Sleep: Unlocking the Power of Sleep and Dreams by Matthew Walker(6679)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5533)
Sapiens by Yuval Noah Harari(5343)
The Body: A Guide for Occupants by Bill Bryson(5064)
The Longevity Diet by Valter Longo(5048)
The Rules Do Not Apply by Ariel Levy(4931)
The Immortal Life of Henrietta Lacks by Rebecca Skloot(4564)
Animal Frequency by Melissa Alvarez(4442)
Why We Sleep by Matthew Walker(4415)
The Hacking of the American Mind by Robert H. Lustig(4355)
Yoga Anatomy by Kaminoff Leslie(4342)
All Creatures Great and Small by James Herriot(4293)
Double Down (Diary of a Wimpy Kid Book 11) by Jeff Kinney(4252)
Embedded Programming with Modern C++ Cookbook by Igor Viarheichyk(4160)