Hello, my friends, in the previous video, we have learned how to create a plain old Java objects
from JSON file, so we have pasted this JSON file example and we have selected these in order to click
on the preview and get this example class.
There are a lot of annotations like expose and serialized name.
These are for far from the annotations package inside the JSON library.
And by the way, JSON is a Google lock.
So what is Jason and what is the use of it?
We're using that with that retrofit.
When we select the annotation style, we selected the GS.
So what are the juice annotations and what is that JSON library?
Jason is a Java library that can be used to convert Java objects into their JSON or presentation.
So if we go to GitHub dot com slash Google, says Jason, we can find this repository and we scroll
down.
There is a lot of documentation about that, and we are going to make an app that uses that JSON and
our examples using the retrofit will probably, most probably we are going to use the JSON.
It can also be used to convert it JSON string to an equivalent Java object.
Jason can work with an arbitrary Java objects, including pre-existing objects that you do not have
source code off.
This is.
We are not going to deal with we are going to create there and that objects from these Java script object
annotations.
OK.
So if we go down, we can get provide simple to Jason and from Jason methods to convert Java objects
to Jason and vice versa, allow custom representation of objects, extensive support of Java genetics
and so on.
So in order to add edit, we can add the dependency or if you are using the maven, but we are mainly
using the implementation of the crab.
OK.
And there are a lot of documentation and the theory was provided by this site.
But our main purpose is to understand that it is JSON is a Java serialization and these serialization
library to convert Java objects into JSON and back.
Now let's go back to the annotations here.
If we click on the generating and we go to here, we have that serialised name and the exposed annotation,
what does this mean?
Serialized name annotations tell Jason and comfort there that this member should be serialized to Jason
with the provided name as it's field.
So this is the not name and the name of the member, which is called user I.D. And it should be it serialized
in the same way because it is user I.D. So we are providing and creating this member.
It should be as this name and they are, by the way, equal.
OK, but in many cases we can use like a different name, but we have serialized name, which should
be user ID.
I can put here like my user I.D., but in the serialized name, I should prefer user ID because all
the objects have been used in user ID.
Serialized any.
OK.
So let me give you an example about how to how a serialized name should be given in different from the
member.
So if I consider a new class called by card model in the serialized name card year and the private and
production year, there is a difference between this example and the previous example.
In the previous example, we have User ID here is same as User ID here.
In this example, we have the serialized name called Card Year, and the name of the member is called
Production Year.
In this example, Java class, named My Card Model has a field called card a year or so.
The production year.
This is the field of the class.
When JSON converter converts this to JSON, then the production year field will be converted as card
year.
OK.
So when I make this into JSON object, it will be converted to card year.
OK.
So this production year member of this class will be referred to as card year inside Jason File.
Same will apply when converting from Jason to Java.
So if I have a JSON file containing the attribute and the data card here, it will be directly converted
into production.
Yea.
Map.
The second annotation is called Expose.
This annotation is optional, comes with two parameters either the serialize and that.
So for example, if we go back to our class, my car model and we put the exposed serialize here, then
we use that serialize equal to fold.
So expose.
Serialize equal to falls, then it will this member of that production year will not be converted to
Jason when Jason convert or converts data from Java objects to chase, and if we use these serialize
equal to false, then it will not be converted to Java when JSON converter converts that data from JSON
to Java.
If you set the exposed annotation but don't set either value specifically to false like we have done
here and there in the example of BoJo.
Then.
It will not make any difference.
So here for that user ID expose, the integer I.D. expose and the string tie to expose this will not
make any difference because it by by default will be quick to add that to drew and will not make any
difference because in serialization and the serialization.
OK, so this is what we have learned about that, Jason, and what we need to learn about the deuce
and library and the annotation in order not to be surprised what we are going to use and deride in the
next videos.
Thank you, guys.
I hope you benefit from this video and support.