From the course: Learning Java Enterprise Edition

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

JSON Processing in practice

JSON Processing in practice - Java EE Tutorial

From the course: Learning Java Enterprise Edition

Start my 1-month free trial

JSON Processing in practice

- [Instructor] In this video we're going to take a look at how JSON processing is used in practice. And in particular how we use it in the Cargo Tracker application. Okay, so let's get started. Let's go back to where we left off at the end of the WebSocket video. If you remember the onCargoInspect method listens for CargoInspect events. The way it passes the Cargo object into the JSON string is by using the stringing model or the JSONP API. Now as you can see we are creating a StringWriter object. The elements that form our final JSON string are written to this stream. We start by creating a JsonGenerator by passing it the StringWriter object. We continue by writing the key and value pairs that we want the JSON string to consist of. You can see that we are constructing the string from different properties of the Cargo object. And that it will have a completely different shape compared to the original Cargo object. And finally we've finished writing to the string with a call to the…

Contents