Join Alex Theedom for an in-depth discussion in this video Work with JSON and Java, part of JSON Processing with Java EE.
- [Instructor] Let's have a look at some of the common usages of JSON in the Java world with a focus on its use in the Java enterprise edition ecosystem. As you are already familiar with JSON, I will dispense with any discussion of its structure. What I want to do is to ensure that you are familiar with the way JSON and Java work together. So let's start by looking at a simple structure like this. This is a JSON object with a property called title, which has an associated text value JSON Processing with Java EE. If this JSON string was represented as a Java class, it would have a structure like so.
As you can see, the JSON property title is represented as a field with the same name. An instantiation of the course class would have the title field value set to the same value as that which you see in the JSON string. A more complex example might include a JSON array like this. This array will be represented as a list typing the Java class as you can see here on the screen; and in a slightly more complex example, we could have a nested JSON object such as the course code JSON object you see here. This JSON string will be represented as a class that has a title, chapters, and course code, has members, and the source code object will be represented by the source code class.
Arguably, one of the most common usages of JSON is in the interchange of data between a client and a RESTful API. A RESTful API implements the REST architectural pattern, where REST means representational state transfer. So, what does this mean? Well, without going into lots of detail, often what this boils down to is the civilization of a plain old Java object represented as a JSON string. We've seen an example of this in the previous slides. The POJO represents a resource within your system, such as a book in the bookshop application or a course in an online training site.
Although it is not required that JSON be used to represent resources, it has nevertheless become the predominantly used technology; and it is within REST that Java and JSON really can be seen to work in unison. Connected with the REST paradigm is the use of JSON web tokens, JWT, to implement security concerns. JWT is an open source specification that can be used across REST-compliant systems and is not just restricted to use in Java applications, but any application that understands JSON. A JSON web token is used to create axis tokens that assert a claim, usually in relation to authorization; but often they are used to pass the identity of authenticated users between systems.
If you would like to know more, then go to the jwt.io website where you will find a lot more information. The next generation of databases are referred to as NoSQL and document stores. They store data in a non-normalized manner in documents structured as JSON strings. So instead of storing data in tables, rows, and columns; the data is stored as JSON documents and often with different shapes. A JSON document is just another way of saying JSON string or JSON data. The terms can be used interchangeably. The rise of this type of data store has increased the importance of working efficiently with JSON in a Java application context.
Luckily, as Java developers, we are well catered for as far as compatible and extensive JSON processing APIs go. Why not have a look at some of the NoSQL data stores listed here. By no means is this an exhaustive list; there are plenty more out there, but you can get started with these. The usage of JSON is growing and having a solid knowledge of the Java enterprise APIs that can be used to process JSON documents is absolutely vital. In this course, you will learn how to use the most important features of the JSON processing API to the point where you will be able to immediately put into action what you have learned.
In this course, discover how to use the Java Enterprise Edition (EE) JSON-Processing API. With its two programming models, JSON-Processing is one of the simplest ways to generate, query, and parse JSON data, and you'll find that implementing it in your projects is quick and easy. Join Alex Theedom as he covers an array of topics, including how to use both the object model and the streaming model, how to traverse a JSON structure, and how to parse JSON data using the extensive builder APIs. When you wrap up this course, you'll be ready to develop with this essential and powerful API.
- Working with JSON and Java
- JSON-Processing API features
- The Java EE JSON object model
- Creating a model from a JSON string
- Building a JSON model
- Traversing the JSON model
- Outputting the JSON model to a data stream
- Parsing and writing JSON data