From the course: JSON Processing with Java EE
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Create a model from a JSON file
From the course: JSON Processing with Java EE
Create a model from a JSON file
- [Instructor] Okay, so go ahead and open up the ObjectExample2 class. In the loadJasonObject() method, we're going to start to write the code in the same way that we did in the previous example, but instead of creating a StringReader, we create a FileReader. So let's start as we did before. We need a JsonReader, and we need to create a factory. We do this by calling a static method on the Json class. In this case, we're going to pass it a new FileReader, and we're going to pass it our jsonFileObject. Now, at the top of the screen, you can see that we have our jsondata-object.json file. This file is located in the resources directory. What the FileReader will do is to open this file and load in the JSON data. Just as we did before, what we need to do is to call the readObject method on the reader instance. So we're going to create our jsonObject instance. We're going to be calling our readObject method, which reads the object, into our jsonObject. Just as before, we need to return our…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Introduction to the object model2m 44s
-
(Locked)
Create a model from a JSON string6m 48s
-
(Locked)
Create a model from a JSON file2m 48s
-
(Locked)
JSON builder API1m 24s
-
Build a JSON model8m 30s
-
(Locked)
How to traverse the model1m 36s
-
(Locked)
Traverse the JSON model6m 19s
-
(Locked)
Output the JSON model to a data stream3m 16s
-
(Locked)
Challenge: JSON array object30s
-
(Locked)
Solution: JSON array object1m 11s
-
(Locked)
Challenge: Write unit test27s
-
(Locked)
Solution: Write unit test23s
-
(Locked)
Challenge: Output JSON object to a file18s
-
(Locked)
Solution: Output JSON object to a file36s
-
(Locked)
-
-