2016-11-09 66 views
1

我已經使用嵌套查詢定義了一個restful服務。輸出映射在XML中定義。我作爲XML得到了適當的迴應。但是,如果我要求使用接受的JSON響應:應用/ JSON我得到WSO2DSS 3.5.1 - 來自REST式服務的JSON響應中的問題

{ 
    "Fault": { 
    "faultcode": "soapenv:Server", 
    "faultstring": "Error while writing to the output stream using JsonWriter", 
    "detail": "" 
    } 
} 

我得到異常低於3.5.0,我發現一個JIRA說,它是固定在3.5.1。所以我在3.5.1中試過,現在我沒有得到異常但是輸出相同。

javax.xml.stream.XMLStreamException: Invalid Staring element 

請注意,我也試圖在我的查詢,但沒有使用escapeNonPrintableChar="true"選項。奇怪的是它適用於不同的數據集。只有一個特定的數據集正在拋出這個輸出。

我已經改變了JSON格式化程序如下,並得到它的工作,但有一個問題。

<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/> 
<!--messageFormatter contentType="application/json" class="org.apache.axis2.json.gson.JsonFormatter"/--> 

<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONOMBuilder"/> 
<!--messageBuilder contentType="application/json" class="org.apache.axis2.json.gson.JsonBuilder" /--> 

如果我使用上面的格式化程序,則空值不能正確表示。就像我得到

"Person": { 
      "Name": { 
      "@nil": "true" 
      } 

,但我想它(比如用來給其他JSON格式)

"Person": { 
      "Name": null 
      } 

任何幫助,請。這個區域還有一個bug嗎?

回答

3

當您在輸出響應中創建查詢時,您可以定義要接收響應的格式,您可以選擇xml或json,如果您提到可以選擇json選項,則選擇generate response this create這個json結構。

{ 
"entries": { 
"entry": [ 
{ 
"field1": "$column1", 
"field2": "$column2" 
} 
] 
} 
} 

然後你可以修改你的字段所需的答案。下面是我如何使用它在我的查詢

{ 
"Pharmacies": { 
"Pharmacy": [ 
{ 
"ID": "$Id", 
"Descripcion": "$Desc", 
"Latitude": "$Latitude", 
"Longitude": "$Longitude", 
"Image": "$Image" 
} 
] 
} 
} 

值以「$」的一個例子是對應於查詢

關心的列的名稱