[MUSIC] It can be helpful to understand how Spring actually converts our objects that we return from controller methods or that we pass into controller methods, back and forth from JSON. So let's say that we have a controller method like, let's call this Video createvideo and we will pass in a video. And I'm going to leave off the annotations and other things. And we assume that there's a method body here that does something. So, the idea is we want the client to be able to, through some request path. And you would assume there was some request mapping here. There's at response body in this video. There is at request parameters or at request body or whatever it is, on this, video parameter. So we're basically, we've already created all of the infrastructure. To make this method accessible, [UNKNOWN]. Now, one of the questions is how do we take in a video from JSON, and then how do we return a video and convert it back to JSON. So this is going to JSON and Spring probably, and this is going from JSON. So, what is the default mechanism or approach that Spring uses to convert to and from JSON? By default, to do this, Spring uses a open source project called Jackson and these, conversions are part of an, a thing that Jackson supports called the object mapper. And the naming is a sort of a give away of what this thing does. It maps objects to JSON and it maps JSON back to objects. So, with an object mapper, we can go and say, convert this object into a JSON string or take this JSON string and convert back into an object and we just tell Jackson what type of class we're expecting that JSON string to be and then it automatically goes and constructs an object. So, let's look at an example of converting from JSON to an object with Jackson. First, we need to define our video object or our video class that we're going to be operating on. So we'll just have a video and let's give our class a couple of member variables. Let's have a, string title and maybe private string. And you could have whatever you wanted URL. Now, just to be more interesting, let's also add a length to our duration to our video. Now, you can imagine that we would go and create some getters and setters for these properties so we would have public, String getTitle. And similarly, we would have getDuration, we would have getURL, and we would also have setters. So, we would have public void setTitle. It would take the title in as a parameter. So, if we had this object, we would like to be able to map JSON into instances of this object. So, let's say that we have JSON that looks something like this. So, we have a JSON string that looks like, we're just going to create this object and we're going to have title Coursera and then we might have duration, some duration 12345 or something like that. And we would have maybe URL, and we have some URL for this thing. Now, what Jackson does, is by default, you can tell it to go and convert JSON into instances of a particular class. So in this case, we can go and convert this JSON into an instance of video. And the way that Jackson does this is first by default, it expects video to have a constructor that takes no arguments so that it can construct a new incident. So, what Jackson's going to do is it has a method called read value that will basically take this. It will call the constructor for video. It will create a new video object and then it will call, as it walks through the JSON, it will call setTitle and it will find setTitle method. It will call setDuration and setURL. And each time it finds a new property on the object in the JSON, it will look at the appropriate type for that, parameter or member variable of the objects based on either the return type from the getter or the value that's being passed into the setter and the type of parameter being passed into the setter. And it will automatically look at that and figure out how it needs to convert from the string or number here into a call on the setter. So, it's a lot like what our Spring controller is doing where it's automatically, you know, constructing our controller objects and calling methods on them. In this case, the underlying Jackson framework is going and looking at the different pieces of JSON and then automatically constructing objects that we tell it to construct and then mapping the different properties in those JSON objects to the getters and setters inside of our class. So, this will end up calling setTitle. It will call setDuration. It will call setURL. And it will automatically convert the values. The other interesting thing about Jackson is let's say that video had embedded reference to some other object. So, lets say that there was a video type object. Jackson, if it saw a property that was video type and then specified a new JSON object embedded within it, it would automatically extract that object, look at the type that was specified in video where it would say video type and then it would construct an instance of video type before passing it to video. So Jackson can go and take an entire hierarchy of objects or tree of objects specified in JSON and convert them into Java objects that we specify through a series of classes with getters and setters and, by default, no argument constructors. So if you ever go and see some strange errors from Spring, for example, it may say, oh, well, your, your format is incorrect, or if it sees that there's a property here that's not in the class, Jackson will throw an exception saying some property that it was expecting wasn't on the class, or vice versa you can have properties that are required in the class that if they're not present in JSON it will throw exceptions. But, Jackson takes this process of going from this to instances of that, and automates it, so that you don't have to write all of the code to do that. And Jackson is what's sitting underneath the covers in Spring, providing this ability to automatically take your response body from a controller method and return it back into JSON or take JSON as being sent as a parameter to a controller method and convert it into an object. One of the other things is, you can go and control how Jackson converts your objects to JSON and can goes from JSON back to your objects through a series of annotations. So, you can do things like @JSONIgnore to tell Jackson properties of your objects that you don't want converted into JSON and brought from JSON back into your object to help it know things that you don't, care about. There's also the ability to go and specify certain properties that you would like to name differently. So the default naming scheme is, it's going to take a property, it's going to title case the first letter of the property. So, it will go get plus it's going to take the first lev, letter and upper case it. So, that gets converted into getTitle. If you had Foo here, that would get converted into getFoo. And similarly, if you have a setTitle or a get, if you have a getDuration method that's automatically going to become the JSON properly duration. So, you can also use annotations within Jackson to control the naming of the JSON that gets produced or the JSON that gets consumed and mapped to your objects.