Step 2. Define custom JSON Types

INT010A - JSON Service - Define Server-side logic

JSON Types are user-defined data types used in a JSON agent or server to define request and response parameters. They can consist of one or more elements, each of which may be of a simple type such as strings or numbers.

Defining them using LANSA Integrator Studio makes them independent of the web services that uses them.

In this step you will define the type for Employees.

1.  Select the tab for your Project in the LANSA Integrator Studio.

2.  Select Solutions and right mouse click to open the context menu.

3.  Select the JSON Server types option from the menu.

     This will open the LANSA Integrator JSON Type Editor.

4.  Right click in the empty space to open the context menu and then select New Type.

     The LANSA Integrator JSON Type Editor dialog is displayed.  Type Employee.

5.  Enter the name for the new type in the LANSA Integrator JSON Type Editor dialog box and click OK (or press the Enter key).

6.  Now you must define the elements that make up the Employee Type.

     To define an element:

a.  Right click on Employee to open the context menu.

b.  Select New Element from the context menu.

     The Element dialog box is opened.

7.  Enter employeeId as the Element Name of the first Element. Note the case of this entry. The first character is lower case. The first character of other words (in this case Id) is upper case.

     Select the Value String from the drop down list.

8.  Press OK.

     The dialog remains open ready for you to enter any further elements.

9.  Enter the second element in the same way as for employeeId:

     That is, firstName with a Value of String.

10. Create the third element, the salary element.

     The Value for salary is the appropriate numeric type which is double.

11. Create the final element, surname with a Value of String.

12. Close the Element dialog box by clicking the Cancel button.

13. You will now add another type. Right click in the empty space to open the context menu and then select New Type.

14. Enter the type Employees for the new type in the LANSA Integrator JSON Type Editor dialog box and click OK (or press the Enter key).

15. Now you must define the elements that make up the Employees Type.

     To define an element:

a.  Right click on Employees to open the context menu.

b.  Select New Element from the context menu.

     The Element dialog box is opened.

16. Enter employees as the Element Name of the first Element. Note the case of this entry. The first character is lower case.

     Select the Value Employee […] from the drop down list, which indicates the response will be an array of employees.

17. Press OK.

     The dialog remains open ready for you to enter any further elements.

18. Close the Element dialog box by clicking the Cancel button.

19. You will now add another type. Right click in the empty space to open the context menu and then select New Type.

20. Enter the type EmployeeDeptSect for the new type in the LANSA Integrator JSON Type Editor dialog box and click OK (or press the Enter key).

21. Now you must define the elements that make up the EmployeeDeptSect Type.

     To define an element:

a.  Right click on EmployeeDeptSect to open the context menu.

b.  Select New Element from the context menu.

     The Element dialog box is opened.

22. Enter departmentCode as the Element Name of the first Element. Note the case of this entry. The first character is lower case. The first character of other words (in this case Code) is upper case.

     Select the Value String from the drop down list.

23. Press OK.

     The dialog remains open ready for you to enter any further elements.

24. Enter the second element in the same way as for employeeId:

     That is, sectionCode with a Value of String.

25. Close the Element dialog box by clicking the Cancel button.

     You have created the JSON Types necessary to support your web service.

26. Save the changes using either the IconSave Save button, the Ctrl + S keys or Save from the File menu.

27. Close the LANSA Integrator JSON Type Editor using Exit from the File menu or the Alt + F4 keys.