Java: JSON Fundamentals

JSON is one of the most widely used human-readable data interchange formats in the world. This course will teach you how to generate and parse JSON, what it can and should be used for and how to integrate it into other projects.
Course info
Level
Beginner
Updated
Jul 30, 2018
Duration
2h 29m
Table of contents
Description
Course info
Level
Beginner
Updated
Jul 30, 2018
Duration
2h 29m
Description

JSON is one of the most widely used human-readable data interchange formats in the world and understanding how it works is important for developing server-side Java applications. In this course, Java: JSON Fundamentals, you will learn everything about JSON that a Java developer needs to know. First, you will cover what it can and should be used for. Next, you will learn how to generate and parse JSON including binding, streaming and DOM/Tree style APIs. Finally, we will look at the big picture of JSON: how to integrate it into projects and appropriate information architecture principles. When you've finished this course, you will have a strong understanding of how JSON can be used in real-world server-side Java projects.

About the author
About the author

Software Engineer, Trainer, Author and Conference Speaker, interested in deep dive performance issues, PhD, Londoner.

More from the author
Java Interfaces and Abstraction
Intermediate
1h 58m
Sep 1, 2017
Understanding and Solving Java Memory Problems
Intermediate
2h 40m
Mar 28, 2017
More courses by Richard Warburton
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone. My name is Richard Warburton, and welcome to my course Java: JSON Fundamentals. I'm an independent software consultant and co-founder of Opsian. com, a low overhead production profiling solution. JSON is one of the most popular formats for serializing data into and is really commonly used by Java programmers, especially for talking to front-end web applications. Some of the major topics you'll learn about in this course are as follows, what JSON is used for in the context of Java application, how to take Java objects and produce JSON documents from them in an easy and maintainable manner, how to consume JSON documents and ingest them into Java objects, what are the best practices of information architecture for using JSON with Java. By the end of this course, you'll know how to use JSON in real-world Java applications and be really productive with it. Before beginning the course, you only need to be familiar with core Java programming techniques. No familiarity with JSON is assumed. I hope you'll join me on this journey to learn JSON with the Java: JSON Fundamentals course at Pluralsight.

What Is JSON?
Hello, and welcome to this course on JSON fundamentals in Java. I'm your host, Richard Warburton. I hope you're as excited to be watching this course as I am to be producing it. Now this is the first module, which is entitled, What is JSON? Now just to make sure that you're in the right place, I should say that I'm not talking about the actor who played George on Seinfeld, the guy who played Marshall Eriksen in How I Met Your Mother, or even the guy in Arrested Development. We're not answering the question who is Jason. Where answering the question what is JSON. Now JSON is an acronym and it stands for JavaScript Object Notation as it provides a language independent and human readable data interchange format. Now even though it originates from the JavaScript ecosystem, JSON can be used for interchanging data between different languages that aren't just JavaScript. A particularly popular use case from the point of view of Java developers, sending or receiving data between a Java server or a JavaScript web client. Now were going to break out what I think are the three biggest use cases for JSON within the Java world so that it's clear whether and why you should be using JSON.

Producing JSON
Hello, and welcome to module 2 of the course. In module 1, we looked at what JSON was and why you might want to use it. In this module, we're going to progress to producing JSON, i. e. taking data from Java objects and producing serialized JSON data out of them. Now, like everything in life, there are many ways of producing JSON. No one way is perfect for all situations, and some are never a good idea. The first approach you'll encounter, which is a bit of an anti-pattern really is the manual manufacture of JSON. So we're going to do some string concatenation, some formatting, and we're going to produce some JSON strings. Now I'm showing you this so you can see why it isn't a very good approach. Then, you'll learn about the generator API. This is a light-weight API for producing JSON documents. It's very simple to get started with, but it still leaves you with a lot of work to do and some ongoing maintenance burden. Finally, we'll take a binding API approach. The binding API approach is one that will automatically serialize your Java objects into JSON. So there's a really simple API that takes a lot of the work out of producing JSON.

Consuming JSON with a DOM API
Hello. I'm Richard Warburton, and welcome to module 3. This is entitled Consuming JSON with a DOM API. This is the first of three consecutive modules where we start talking about how we consume or parse, as it's sometimes referred to, JSON. So that's going from having data encoded as a string on a connection or in a file to having it in-memory in your Java application. We'll proceed in three parts. First, you'll get to learn about what we mean by a DOM API and why you want to use an API rather than hand write a JSON parser. Then, I'll live code with some Jackson demos. That way you'll get to see what the API is like in practice and understand how to use it. Finally, we'll talk about situations where you want to use a DOM API rather than the other two styles for parsing JSON.

Consuming JSON with a Binding API
Hi there, and welcome to module 4 of this course. In this module, we're going to talk about the simplest and most commonly used way of consuming JSON documents in Java. And that's using a binding API. So, we've looked at how you consume JSON with a DOM API in the previous module. That was a document object model API. That worked fine, so what was the problem that existed there that we solve using a binding API? Now, the idiomatic Java approach to modeling a domain event or a message is to use a POJO. That stands for plain old Java object. Java classes that define POJOs will just store their property values and fields, and each field will have a getter and a setter with the same naming convention as the field. As a Java dev, you're probably pretty familiar with this idea by now. Using a POJO to store values in the field also ends up encoding the same structure as a JSON object. JSON properties are storing the same information with a different convention as the Java field plus getter and setter approach. If you're using a DOM API for JSON and converting that to a POJO, then you're inevitably going to have to write a lot of boilerplate code, which is just extracting these values from the JSON and setting them into the POJO with the same name. This is time consuming, tedious, and error prone to write. A binding style API takes the approach of auto-generating this mapping code from the structure of the POJO object. So you just ask for JSON to be converted into a POJO and it does it for you.

JSON Information Architecture
Welcome to the penultimate module of this course, Information Architecture. This is a module that isn't just about the Java APIs for producing and consuming JSON, but more overarching concerns. In order to understand why this module is important, it's worth taking a moment to understand what information architecture is. This is about the big picture design of how we lay out our data in JSON documents. In this module, we're going to look at a series of principles related to JSON that help us write easier to maintain applications and systems.

Integrating JSON
Hello, and welcome to the final module of this course on JSON with Java. In this module, you're going to learn more about integrating JSON with existing web frameworks and also cover a few summary topics. This will help you save time and be more productive when using the most common Java frameworks. We're going to cover a couple of key integration points in this module. Firstly, we're going to look at how to integrate JSON parsing with Spring, a very popular framework for web development. You'll see how to integrate it with Spring Web and Spring Boot. Then we'll look at how to integrate JSON with JAX-RS and Jersey. JAX-RS is a commonly used standard approach for the development of web services that produce JSON and XML. After this, we will evaluate some alternatives to JSON. JSON is really commonly used as a serialization format in both the server-to-server and server-to-JavaScript client use cases. In the former case, there are several serialization options that can offer more features, schema support, and performance than JSON. And finally, we'll wrap up and conclude the course.