1
votes

i am using postages Db for my services.When Null defined for any fields DSS giving Some object so my front end also getting same object .But they are expecting "NULL" instead of this they are getting {@nil":"true"} How can i get NULL value As NULL only and its creating its own name space also for this row http://www.w3.org/2001/XMLSchema-instance"

username        password
===========  ============
NULL            NULL
kk             a123

for above i am getting like this fro WSO2dss side

<Datalist>
     <username xmlns="http:sps.in" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <password xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
  </Datalist>

from my wso2esb side i am getting JSON like this

{"Body":{"Datalist":{"username":{"@nil":"true"},"password":{"@nil":"true"}}}}

But my front end service expecting in this below format where can modify for above this

 {"Body":{"Datalist":{"username":"NULL","password":"NULL"}}}
2

2 Answers

1
votes

In XML, the standard/recommended way to indicate that the value of a particular XML node is NULL, is via the notation [xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"]. If any standard XML parser comes across this particular notation, the element which contains the aforesaid notation is treated as an element with NULL as its value. This is particularly useful, when there are values such as "NULL" (not the actual NULL but a string containing the characters, "N","U","L","L") as there's no way to distinguish the real NULL values and "NULL" character streams.

Therefore, the best way to handle this scenario would be to check for @nil attribute at client side while parsing the JSON content that returns as the response of the web service invocation. Alternatively, you can add an XSLT transformation at the data service query level to transform the response (in XML format which gets processed internally within DSS before returning JSON content) the way you want so that you'll be able to add any custom rules and transform the response before it is returned to the client side. You can refer to the sample data service named "ExcelSampleService.dbs" located in "DSS_HOME/samples/dbs/excel/" directory in the product package for an example on how this is done.

Hope this helps!

Regards, Prabath

0
votes

It worked for me. I just put that two atributtes (xsi:nil, xmlns:xsi) into my XML by changing my AS (Application Server) like this:

public static OMElement addAttributeNull(OMElement parametro){
    parametro.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", null);
    parametro.addAttribute("xsi:nil", "true", null);
    return parametro;
}