Technical Blog Post
Abstract
REST API Java client for B2BAPIs - How to make JSON input for complex data types
Body
If you are looking to implement Java based REST API Client to invoke B2B APIs, my previous articles would help you. These include working java (REST API Client) classes for 2 of the APIs.
REST API Proof Of Concept - Automate Sterling FileGateway Community and Trading Partner creation
REST API Client - upload message to Sterling B2B Integrator Mailbox
These articles covered how to generate JSON input string for primitive data type based parameters. I never used complex data types in previous articles as they were not needed there. I am going to provide sample code here for complex data types such as Collection Set.
Like previous articles, this one too targeted for Java coders.
B2BAPIs/svc/sterlingconnectdirectnetmapxrefs/
{ |
net.sf.json.JSONArray jsonArray = new net.sf.json.JSONArray();
net.sf.json.JSONObject obj = new net.sf.json.JSONObject();
obj.put("nodeName", "NODE1");
jsonArray.add(obj);
obj = new net.sf.json.JSONObject();
obj.put("nodeName", "NODE2");
jsonArray.add(obj);
obj = new net.sf.json.JSONObject();
obj.put("nodeName", "NODE3");
jsonArray.add(obj);
JSONObject nodeJson = new JSONObject();
nodeJson.put("netMapName", netmap);
nodeJson.put("nodes", nodes);
B2BAPIs/svc/codelists/
{ { |
JSONArray addcodes = new JSONArray();
newcode.put("text9", "new9"); //Repeat same for 2nd list. I am not doing it here addcodes.add(newcode);
JSONObject codelistJson = new JSONObject(); codelistJson.put("codeListName", "IBM.CL"); codelistJson.put("codes", addcodes); codelistJson.put("comments", "testing");
|
UID
ibm11120533