Hello, last video I show you how you can call the RESTful web service from a Java program and how you can display the result in the console. As like this. In this video, I will show you how you can map this output to a Java object to that you will be able to displace is that in the ADF pitch to make this map or use JSON library, the right to call Jason this library will be responsible to map the JSON format to an object in the Java class. So to finish this tip, I will do now I will to import this library in the view controller controller. So I will double click here library and the class pass I will add sure and I will point to my measure called JSON or 1.92. jar. This is you will find this jar file interesting source code.
So, I will select and I add this jar file in this project. So, I will be able to use the JSON to map the output to the Java class. The second question here is how I can define the class which will receive the output. So, actually first thing you should call surrogate method, this is try to call it here and you should have a look in this output and you should decide which information from this output you want to receive. I need to receive lists of department because I have here to admit 123 So, I need list of departments to be returned to be mapped to my Java class. So, I will define first a department.
After that I will define class has lists of department and this class will be used to maps output The list full of service to this class. So the first thing now I need to define plus has three attributes department ID, department name and location and Jackson will map this field to this clause. So let us hear defined new Java class. I can call this depart mint okay. So this department has three tribute or property string part ID private string domain name, private string location UD because this is the three information which we want to get from the output. After that, I will just degenerate here accessors setter and getter so that I would be able to call this in setter and getter, okay?
So, this is only one department, but actually I need a list of departments. So, I need a list of this class. This is why I will create a new class here called items because items has a list of clause. So I will call this clause items actually you can call it any any name, but I will call it items so that it will be same like I will format Okay, as this items will have a list of can emboss it Java dot util dot List of T bar men just have to Botwin and they can call it deport mints can find your private list of departments departments and I will generate accessors, setter and getter forces. So actually, this is output of subsurface, which we need to map it to this clause. So, I need the JSON library to receive this items and map it to this and to fill this list of department.
And I will use this list of department to displays a table is the ATF page. Here, I can Just a simple, empty page called dips from risk. This is just an empty page I need to display data from this and I just generate backbeat. Here, empty bank bean. If you don't know how to generic back pain you can select the form and in the advanced binding, you can press edit, here is a Manage button you can press new and you can define a new pin and a new clause and the brace okay? After that press cancel, cancel because you just need to display the backbeat to carry the bag.
So, I have created just empty beach and a bag been for this page. And I need to write code here to call the web surface and the maps the output of this web service to this item class. Then I get this list of department and I need to fill a table in the ATF page to display that from back being as a table in a page it should be in a list. So, I will I will I will now create a new list of departments department because I need a list of department to be displayed list of department table D bar mints, okay. So this actually will be used to map to the F table in the page. So if bt was a visual map to this poverty table departments which will be lists of the departments taught you to do this okay and I will generate here sitter and Get.
Now, I need to generate I need to write a function which we'll call the surface and the map the output of this web service to our cross. So I will create here, private. This method should return the list of departments which we need to fill the table. Get a list of the forum. List, web surface. Okay.
I would add here, try and catch if you don't know how to I did it you can just drop Try and Control Enter it will print it okay. So here I need to call the whip surface. So I will call Strank wrist I would put equal, I write the code here is the common utils. So we can call common utils dot invoke get missiles. So I will say here common util dot invoke method. Here I set the limit 20 to return 20.
Department datas import common util. So now I invoke the web surface and after I invoke those surfaces return dummies out here I need to map this out to this Item class after that from this item clause, I need to get a list of department and I should return it to make this map I will use the Jackson library as I told you. So, to write this code, let us try to read the code. So, this is the code object mapper it will get it from the axon library. So, let us import it Okay. Here it will read the rest output and it should be mapped to our items class.
So, here's the map will have been mapped this output from the restful to the item clause and return it as an items. Clause and the from the item clause wants is a map is happening I need to return So, departments So, I will say tips though Get a deport so it will return list of departments This is what actually I need. So I call the web surface it written out as a JSON format. I use JSON member clause this Jason member will reads output of the resources whoops surface and it will map it to the item clause. But there are two things here first, how z will know that this property department ID should be mapped to this department ID. So you have to right here annotation over each attribute to 10.
Subjects one, which attribute because here you can write any name. You can write here any name but the house is excellent Know this value of the department ID should be mapped to this attribute or this property. So, to tell them that you should add here notation call Jason bro Verity. And you give them the property name, which will return the from the wrist here like this. So, and we will import it from this JSON library as well. Like this.
So, here, the Jason will know that this value was the department ID will be set to this department ID. So it does do the same and as our properties. So, here is the department name you can take this here location ID location It and we should do the same in the main items here because we need to map the main parent items to this so now we are able to tell the projection you should map the main build items to this bottom and inside this departments you should map this attribute to this purchase okay so the second thing is missing is zero also since we didn't map select links we don't want it so we didn't write anything school link is and this thing is has its Sheriff coin name because we don't want it but the Jason Jackson will return error if you don't tell him ignore any on the fine you can add this configuration display who just tells a map configure that for all unknown property just ignore it.
So, here you can ignore any undefined tags like this links sheriff. So the Jackson will ignore this and they will take only the properties which we defined it here. Okay, this is a map how it works. If there are any exception here we just we can return a new ArrayList just an empty array list, because this function should return a list of department. So, if any exception here or has a function didn't turn anything just return Java util dot ArrayList as an empty list where we should call this method, we can call it in the getter of their table department, this is a getter of table department. So, we can call this here we can call a return or in case just one time, you can see if it was meant to equal equal none.
If it is non CIT department, it would equal to this. Okay, so now we are able to call the wolf surface what is missing? here so you should return so can return your list. So here we call the surface we use Jackson library to map the JSON output with my class and from my class I will return the list of the departments. And I will use this list of departments to displays a table. So the last thing is we need to add a table is the page itself.
So to do this, you can just add it if this is table and this table will have only three columns, which we need to display, department ID, name and location here, so you can make it exist now and the value of this table should be table to both Miss in the back me. So, I will go to the property the value will be my been table departments. So it will take the value from a table the bottom is poverty in the back been to give the value of the economy you can here at rho dot and you can take the first one which is a department ID and you can sit the header of the tickets report mean ID to the header or the second one will be the bar mean Name. And it will take it forms a property called department name and location, ID and it will take it from a location ID.
So let's now try to run and see how it will look. So as you can see here, it returns the list of the departments as you can see from the web surface and it returned that 20 row because in the web surface here, we set a limit to 20 in the back been when we call the web surface, which is a limit to 20. So if you make a limit is only maybe 10 and run again it should get only 10. So here it returned only 10 row. So this is the way how you can call a RESTful web service your application in a programmatic way. As you can see here, we add two generic function now, one for invoke rest one for invoke the post rest, you can call it anywhere in your PDF application, just send the URL and use the JSON to map the output of the web surface to your class.
And once the data is received in your class, you can use it anywhere in your ADF application. So in this video, we will talk about how you can add security to you today. RESTful web service. So see you next video.