Welcome back and this video we are going to check out.
Jason and Jason is a library that allows us to work with Jason objects.
So Java Civilization, Civilization and library to convert Java Object into Jason and back.
Perfect.
Jason is a Java library that can be used to convert Java objects into their chosen representation,
and it can also be used to to the other way around.
So that's exactly what we need.
And you can see in order to use it, we need to add the dependancy here in Gradle and yeah, let's just
do that.
So let's go over to our project and then go to the build gradle down to the dependencies here.
And let's just add this.
I'm going to put that in here, called Jason, Jason or Jason, so sing now this will download everything
that we will need for Jason.
And Gradle needs to rebuild.
Of course.
Once that is done, I will go ahead and make my life easier by, first of all, putting some effort
in.
So I'm going to create a new class here, which will be called response.
Data.
So this will be a data class.
And it's not a class, it should have several.
Values and in this case, it will be variables, of course, so value message will be of type string
then what else do we have in our JSON file?
Let's look it up, we can see we have the user I.D. to name the email the mobile, then we have another
Jason object, which will be the profile details, which is also its own class, so to speak.
And then we have the data list, object or data less detail object.
So this is another different type of class.
So let me just paste that in and explain what's going on.
So what I did here is I just created a response to the data class, which contains the different key
names.
OK, so we have the key message, Kinnane, user name, email, mobile provider details and data list.
Of course, we want to store values behind those keys, but we make our life easier by using a model,
which is this response data.
It's a model of our response data and we can then use it very easily when downloading the data from
the website that we're using.
So whatever website it is, in our case, it's this mock up site.
But let's say it's a weather site or it's a football results site or whatever, then we could also just
prepared a model like that.
But you can see something that is a little more complicated than that is this vol profile date details.
So we have profile details, which is another class, and then we have data list, which is actually
a list of data list details, which is this class here which has an ID and a value.
OK, so it's basically the same thing that we have here when we look at our Jason representation.
OK, so here we have the message, the user profile details.
That's where it becomes interesting is an old class.
So it's another Jason class here or Jason object.
And then we have the data list, which is a list of data listed details.
So these are data list details, so to speak.
OK, so it has an ID and that has a value.
All right.
So.
You can see that here we used a list, key word, so this is the it's a more complicated part, but
I wanted to have that in there so that you really understand this part of it as well.
It's very important to also see how you can handle this from Jason Philes.
All right, and now how does that even change our future work?
Well, let's look around main activity and all the way down, we had all of this effort that we needed
to put in.
So, for example, when we wanted to get the message, well, we used to substring and then we got the
message and then we could log it.
But then the beauty is it can be done a lot easier when using Jaeson.
So let me show you real quick.
I'm going to create a new Jaeson variable, which I'm going to call response data, and that will be
Jaeson.
Thought from Jason, and then we need to put in, well, import, Jason, first of all.
So, Jason, here, important then we need to put well, you can see there are multiple different options.
So, Jason Elliman, Jason Reeder, Reader String.
So we have a string.
Right to our result is a string.
So let's pass that in there.
Let's pass the result, which is our Jason files, so to speak.
And then we need to map that with the data class that we prepared.
So here I'm just going to map that with a response data, which is a class.
And I used that Java.
OK, so what I'm saying is, is the response data as the model for the result that we have here?
And it's going to meet that, so it's going to map the different variable names that we have here with
the variable names of our.
Jason, data to get here and now we can go ahead and use it.
So now instead of creating this message variable and getting it from the Jason object lobstering, we
can just go ahead and say, log that I is going to be message, which will be our response data, that
message.
Again, and like that, I can go ahead and do that with all the other variables as well, so I can now
access a user ID with this approach to name, to email the mobile number, everything.
And when it comes to the profile details, and that is where it's a little more interesting there,
I can just go ahead and say profile or response data.
Profile details, dot his profile completed.
So here.
We asked us to profile details and in the profile details, we access to variable is profile completed.
So that's how easy it is done in Jaeson.
That's really amazing.
And the same goes for the ratings.
So higher profile details are rating.
And now if you want to access elements from a data list.
Then we have to use the following approach to can see here we use data, tell us that indices so for
item in response data, that data list indices and then we get the value, which is the response data
list item, and then we get the ID of it and the value.
OK, so similar to what we have done before with this for loop here, but now we are using Jaeson,
which makes our life a lot easier.
So we don't need to create objects all the time.
But we just have one response data object which we then can use in order to get the data very quickly
and access it very easily.
All right, and now let me comment this whole part out here up to the point where we had the follow
up here and run it as well, I'll run it again just to see if it's going to work just the same.
All right, so the cradle is done building.
Now let's look for.
Here, not Jason, but, for example, the message.
And you could see we get the message here, you have successfully logged in and then if we look for
the user, you can see the user I.D. is there.
Let's say we want to name the name.
Is there everything OK?
So now, of course, you can also just look at everything.
Social only selected the application and then you will find that it will pretty much give you all the
data.
A little overhead is in there as well, but it's still pretty good stuff.
So you can see mobile rating value data, less details and so forth.
So you can see it's a lot easier or quicker to use JSON.
And you also have the data model directly here as well, which is pretty clean and that is the improved
and best practice approach, so to speak.
OK, so I hope you enjoyed this part.
We are going to use that quite a bit.
Of course, in the future, it's going to be important to understand all of that.
But if you didn't get it completely, no worries.
We're going to have some more examples for this.
So see you in the next video.