Powered By Blogger

Jul 25, 2016



WSO2 Data Mapper - Creating JSON Schema


This post describes about using WSO2 Data Mapper Diagram Editor to create a JSON Schema by adding elements to the Data Mapper tree view

Applies to        : Runtime -WSO2 ESB 5.0.0
                          Tooling -WSO2 Developer Studio ESB Tooling 5.0.0

Prerequisites  : Install WSO2 ESB Tool - Refer [1] for instructions


Please find below details about configuring the Data Mapper Mediator

1. Create an ESB Config project
  • Create an ESB Solution project which contains all the required project types by right click on the Project Explorer, New -> ESB Solution Project
  • Then specify a name for the ESB Config Project and select the required projects which need to be created ( eg: Registry Resources Project, CAPP etc)
  • Then you need to create a proxy or an API by right click on the ESB Config Project , New-> Proxy Service
2. Configure Data Mapper Mediator



  • You can drag and drop the Data Mapper Mediator to the created proxy and then can configure the Data Mapper Mediator by double clicking the mediator
  • You will get a dialog box to specify a prefix for the configuration files which will get deployed to the ESB Server. Then specify the prefix and select a Registry Resources Project to save the configuration files.
  • Then click on OK and the Data Mapper Diagram Editor will be opened in the WSO2 Data Mapper Graphical perspective as shown below
(Please refer the section 'Create ESB Configuration Project' at [2] for more information)








3. Generating JSON Schema

Basically there are 4 types of components in the JSON Schema

                      -Arrays
                      -Objects
                      -Fields
                      -Attributes
  • The root element can be either an object or an array so when creating the tree, first you need to add the root element of the tree by right click on the input or output box and then click on "Add new Root Element"
  •  From the dialog appears, add below fields to create the root element
            - Name : a string value defining the element name
            - Schema Type : the element type as array/object
            - Id :  a string value declaring a unique identifier for the schema
            - isNullable : a boolean value specifying the element is a nullable or not  (optional field)
            - Namespaces : an array of objects defining urls and prefix values (optional field)


            - Required : specifies the fields that are mandatory to contain (optional field)
            - Schema Value : custom URI of the schema

  • Adding an array as a child element : if you want to add an array then right click on the parent element and then select "Add new Array"

  • Additional fields for array are as follows
              - object has identifiers : if the object has element identifiers
                (eg:xsi:type) then select the checkbox and add the value, type and url             
                         <urn:sObjects xsi:type="urn1:Contact">
                             <AccountId>001D000000HRzKD</AccountId>
                         </urn:sObjects>
                         <urn:sObjects xsi:type="urn1:Add">
                               <AccountId>001D000000HRzKD</AccountId>
                               <AddId>00001</AddId>
                         </urn:sObjects>


              - object holds a value : if the array holds a value then select the check
                box and select the data type

                            <urn:sObjects xsi:type="urn1:Contact">Object1
                              <AccountId>001D000000HRzKD</AccountId>
                            </urn:sObjects>
                          

  • When adding the element identifier, it is added as an attribute to the element as shown below
  •  Adding a field as a child element : if you want to add a field then right click on the parent element and then select "Add new Field"


  • Adding an attribute : if you want to add an attribute then right click on the parent element and then select "Add new Attribute






 4. Editing the  Data Mapper Tree nodes (JSON Schema)

  • If you want to edit any fields of a node, then right click on the node and select Edit option eg: if you want to edit an object then select "Edit Object"
  • From the appeared dialog box you can update the field values as required
5. Deleting the tree nodes
  • If you want to delete a node you can right click on the node and select "Delete From Model", and it will delete the node with it's child nodes
6. Enable Nullable for tree nodes

  • If you want to make a particular element a nullable, then you can right click on the node and select "Enable Nullable", and then it will make the element a nullable and you can identify that by the icon change
  •  If you want to disable that, then again you can right click on the node and select "Disable Nullable"


[1] https://nuwanpallewela.wordpress.com/2016/04/10/how-to-install-developer-studio-esb-tool/
[2] https://nuwanpallewela.wordpress.com/2016/07/16/how-to-use-wso2-data-mapping-mediator-in-esb-updated/

No comments:

Post a Comment