Map REST JSON Output to a Java Object and Display Result in ADF Page

Advanced Oracle ADF 12c Course Model|Expose Application Module to REST Web Service
19 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.33
List Price:  €91.90
You save:  €27.57
£55.09
List Price:  £78.70
You save:  £23.61
CA$95.29
List Price:  CA$136.14
You save:  CA$40.84
A$104.44
List Price:  A$149.21
You save:  A$44.76
S$94.20
List Price:  S$134.58
You save:  S$40.38
HK$546.10
List Price:  HK$780.18
You save:  HK$234.07
CHF 63.62
List Price:  CHF 90.89
You save:  CHF 27.27
NOK kr751.73
List Price:  NOK kr1,073.95
You save:  NOK kr322.21
DKK kr480.45
List Price:  DKK kr686.39
You save:  DKK kr205.93
NZ$114.09
List Price:  NZ$162.99
You save:  NZ$48.90
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,195.22
List Price:  ৳11,707.96
You save:  ৳3,512.74
₹5,830.20
List Price:  ₹8,329.22
You save:  ₹2,499.01
RM328.07
List Price:  RM468.70
You save:  RM140.62
₦102,885.30
List Price:  ₦146,985.30
You save:  ₦44,100
₨19,393.48
List Price:  ₨27,706.17
You save:  ₨8,312.68
฿2,536.99
List Price:  ฿3,624.43
You save:  ฿1,087.43
₺2,256.71
List Price:  ₺3,224.01
You save:  ₺967.30
B$357.27
List Price:  B$510.40
You save:  B$153.13
R1,265.02
List Price:  R1,807.25
You save:  R542.23
Лв125.89
List Price:  Лв179.86
You save:  Лв53.96
₩94,793.75
List Price:  ₩135,425.45
You save:  ₩40,631.70
₪259.28
List Price:  ₪370.41
You save:  ₪111.13
₱4,039.50
List Price:  ₱5,770.97
You save:  ₱1,731.46
¥10,895.69
List Price:  ¥15,565.94
You save:  ¥4,670.25
MX$1,162.43
List Price:  MX$1,660.69
You save:  MX$498.25
QR253.91
List Price:  QR362.75
You save:  QR108.83
P948.27
List Price:  P1,354.73
You save:  P406.46
KSh9,168.69
List Price:  KSh13,098.69
You save:  KSh3,930
E£3,283.23
List Price:  E£4,690.53
You save:  E£1,407.30
ብር4,009.02
List Price:  ብር5,727.42
You save:  ብር1,718.40
Kz59,310.71
List Price:  Kz84,733.22
You save:  Kz25,422.51
CLP$62,605.89
List Price:  CLP$89,440.82
You save:  CLP$26,834.93
CN¥505.55
List Price:  CN¥722.24
You save:  CN¥216.69
RD$4,078.44
List Price:  RD$5,826.59
You save:  RD$1,748.15
DA9,404.82
List Price:  DA13,436.03
You save:  DA4,031.21
FJ$155.95
List Price:  FJ$222.79
You save:  FJ$66.84
Q543.74
List Price:  Q776.81
You save:  Q233.06
GY$14,641.89
List Price:  GY$20,917.88
You save:  GY$6,275.99
ISK kr9,678.91
List Price:  ISK kr13,827.61
You save:  ISK kr4,148.70
DH693.20
List Price:  DH990.33
You save:  DH297.13
L1,231.95
List Price:  L1,760
You save:  L528.05
ден3,957.99
List Price:  ден5,654.52
You save:  ден1,696.52
MOP$562.43
List Price:  MOP$803.51
You save:  MOP$241.07
N$1,273.79
List Price:  N$1,819.78
You save:  N$545.99
C$2,572.13
List Price:  C$3,674.63
You save:  C$1,102.50
रु9,330.17
List Price:  रु13,329.38
You save:  रु3,999.21
S/260
List Price:  S/371.45
You save:  S/111.44
K271.59
List Price:  K388.01
You save:  K116.41
SAR262.46
List Price:  SAR374.96
You save:  SAR112.50
ZK1,777.13
List Price:  ZK2,538.86
You save:  ZK761.73
L320.28
List Price:  L457.57
You save:  L137.28
Kč1,590.03
List Price:  Kč2,271.57
You save:  Kč681.54
Ft24,925.85
List Price:  Ft35,609.88
You save:  Ft10,684.03
SEK kr750.08
List Price:  SEK kr1,071.59
You save:  SEK kr321.50
ARS$62,063.63
List Price:  ARS$88,666.13
You save:  ARS$26,602.50
Bs483.56
List Price:  Bs690.83
You save:  Bs207.27
COP$266,463.69
List Price:  COP$380,678.73
You save:  COP$114,215.04
₡35,817.30
List Price:  ₡51,169.76
You save:  ₡15,352.46
L1,723.87
List Price:  L2,462.78
You save:  L738.91
₲524,369.02
List Price:  ₲749,130.70
You save:  ₲224,761.68
$U2,697.33
List Price:  $U3,853.49
You save:  $U1,156.16
zł274.39
List Price:  zł392.01
You save:  zł117.61
Already have an account? Log In

Transcript

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.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.