Parsing and Reading JSON Documents in Java Programs | ChargeAhead LLC | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Parsing and Reading JSON Documents in Java Programs

teacher avatar ChargeAhead LLC, Technologist

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

8 Lessons (12m)
    • 1. Overview

    • 2. Audience

    • 3. Prerequisites

    • 4. Tools

    • 5. JSON

    • 6. JsonToJava

    • 7. ReadJson

    • 8. Summary

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

In this course, we will see how to easily generate Java Objects for a given JSON document using jsonschema2java Maven plugin. Next we will see how using these objects we can read the JSON document in our Java program.

Meet Your Teacher

Teacher Profile Image

ChargeAhead LLC



Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Overview: Jason is a very popular direction format. Often times we have a need to read and work with. Jason in our Java program in this course will start off talking about the audience pressure visits and tools needed for the scores. Then we will talk about this on Look at him, even plug in, which helps us generate Java objects for a given just on document. This plug in is the disowns Kimoto Pooja Plug in this plug in makes it super simple Degeneracy Java objects for a given. Jason Schema already zone document. It has a lot of options. We will use this and other moving project to generate a Java objects. We will then show how, using those generated objects, we can read the disown document. We will use that Jackson did a mine deliveries toe map that his own document the Java objects and read them. So by the end of the scores, you should have a good understanding off Jason and how you can easily generate and consume it in your Java program. Let's get started 2. Audience: this course would be suitable for Jammeh, the Clippers and soft. For our critics, this is a course suitable for even someone getting started as I will be taking you step by step through the entire process. It should not be difficult to follow along. And this court will also be useful for experience Java programmers as they will get exposure to some new tools and methods to use in. There's our programs. 3. Prerequisites: to get the most out of the scores. It will be good to have a basic and it's turning off Java. I will be using me even as the bill tool, so some understanding off maven would be useful. However, I will be using the spring tools Feet I D E, which would do a lot of heavy lifting for us and create the basic structure and artifacts, and so should be easy to follow along, even though you do not have a lot of exposure. 4. Tools: we will be working with Spring Tool Suite, which is the flavor of eclipse. However, if you're more comfortable with other I d Ys like intelligent etcetera, please feel free to do so. We'll be using open Judy Kaye Washing 11. I will be using Maven as the bill tool. Also, I will be using the disown schema to Poggio maven Plug in for generation off Java objects. You can find the gold for the demo in the scores at the following get WRL. 5. JSON: this on stands for javascript object. In addition, this on documents are very lightweight. Android an easy did a transfer mechanism. The design structure is built on a collection off name. Value appears, which really is programming languages translates to an object or hash table or a record etcetera. They also comprise off a list of values, which can translate to an array or a list except tre. The name and value are separated by a colon. Lettuce on object begins for the left curly brace and ends with the right curly brace, and a decent structure can have nest ridges. Owns two. The different name Al appears are separated by a comma. 6. JsonToJava: here I have my Spring tool suite open. Let's go toe file New Under and from under Maven Jews Maven Project Choose the default workspace location, click Default are type off quick start and click. Next. Let's give the Group I d as calm down Demo An artifact Ideas just on click Finish. Let's Google Jason to Java, and that brings up on the list. Www dot Jason schema toe Poggio dot org Website Let's click on this, the pro orders and only tool to convert Jason or disown Ski Mountain Java objects. However, we want to do it programmatically. So let's crawl down and click on them. Even plug in this plug in provide such unread goal that it matches to the generate sources . Phase off me even by default. Let's copy this plug in. Let's go back to our project and open the former XML file. Let's add the bill section and pace or plug in our hair. Now the plug in will look under source Main Resources Schema folder from the Dizon Schema, or that his own document. Let's change the target package to calm the damage or disown. That's a pretty project by right clicking on the project and choosing maven and then update project Click OK. It is complaining that it cannot find the source Main Resources Schema folder, so let's create that explain source. Right click Choose new folder Cornet Resources, right click on the resources and choose new folder colored schema going back to the website . It requires Java version 1.6 or higher. Let's copy this and paste this in or plug in. Let's change our release to Java version 11 Going back to the webpage, we see that it also requires a couple of dependencies. Let's copy these. Go back to our project for the Jackson did a bine, please, a great diversion to the latest I have a bridge. Did the sore scored and get help to reflect the latest version of this dependency toward in 2.10 point to the leaders at the time of the recording. Let's former this. Now we want to generate Java objects against a Jason document and not adjacent schema in our demo, so I will indicate that by putting source type as just on now, let's take a look a day over Jason Document lying in the dog's folder first copy to our scheme a fuller Open it and we can see that inside the zone we have the person just on with a few properties and then the cars just on which has a list off charges on objects. So it is a pretty complex just on with Mr J Zones lists except Tre Elgin. Rig double objects for this. Let's right. Click on our project and choose Run as and Jews may even build do the goal as generate sources. Click run! It finishes successfully. Let's refresh our project under target, we see a folder generated sources. Then the sun schema topo. And here is our package structure. Calm down, damn it on his own and we see the classes and generated the ultra most class is de Montreuil Java, which contains the person just on the person. Just zone contains name, age and cars object. So, as we can see here, name, age and in ministered cars. Just on the car's object contains a list of car objects and the car object contains the car properties pretty cool. Where does the generation nicely? Let's test whether it'll work to religious on 7. ReadJson: Let's copy these classes. Tore mean Java node. Oh, I need to change the case off Jason in the package name. Let me do it for all the objects. See of the objects. Good. Let me open after a Java first, let me create object mapper as new object mapper. Let's fix the imports. Let's put everything in a try. Catch block. Add the exception section. Now let's create a type reference for our demo object. The ultra Most Object as new type reference demo, greed and input. Stream in to read the dis on file as file input stream lying in the docks for her. Finally, we get the demo object by calling mapper. Don't read value passing in the import stream and the type reference for providing mapping details. That is it we have successfully ready is on object to demonstrate that let's do a system or print line for person name as Democrat get person. Don't get name now to get the list of cars, for instance, Weaken do demo don't get person, get cars, Get car traversing the disown To get the list of cars, Fix the imports Now Let's it read over the list off cars and print the car brand as card ongoing brand. All right, let's run this by right clicking and choosing run as job application, and here we see that we were able to successfully read the dates on using a virgin rigid objects. 8. Summary: in this course, we talked about the Zone or John script object notation. We took a look at the structure off a Jason document, which is a collection off name value piers and list elements. The name and values are separated by colon, and the name and value peers are separated by a comma within Gen. Richard Java objects for over Jason. Using Jason Schema to put a plug in this plug in can work against both of his own schema as well as a Jason document This plug in for works that generate goal. That attach is to the generate sources Face off me even my default. Next, we took Addison document and the most Richard how to read over Jason Using these generated objects, we used that Jackson did a mine deliveries to map our objects to this Jason document and read it programmatically I enjoyed making the scores and I hope you enjoyed watching it, too. I hope you got a good, honest earning of Jason and hydrogen read and consume it in your Gela programs. I wish you all the best as your plan, this knowledge, the projects you're working on. Thanks for watching