我在序列中使用了JsonTransform中介器,以确保数据库查询中的电话号码字段以字符串而不是数字的形式返回.
<jsontransform description="JSON Transform" schema="conf:custom/mySchema.json">
个
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"nodes": {
"type": "object",
"properties": {
"node": {
"type": "array",
"items": {
"type": "object",
"properties": {
"phone": {
"type": "string"
}
}
}
}
}
}
}
}
问题是该字段也可以为空.如果该字段不为空,则中介程序可以正常工作,但如果为空,则会出现以下异常:
JsonNull java.lang.UnsupportedOperationException: JsonNull
at com.google.gson.JsonElement.getAsString(JsonElement.java:192)
at org.apache.synapse.commons.json.jsonprocessor.validators.ObjectValidator.validateAndUpdateEntriesMap(ObjectValidator.java:349)
我使用JsonTransform是因为我认为这是确保字段是字符串的推荐方法,但在WSO2文档中没有JsonTransform示例,其中字段也可以为空.我试着添加了
<property name="synapse.commons.enableXmlNullForEmptyElement" value="false"/>
个
和
<property name="synapse.commons.json.output.autoPrimitive" value="true"/>
个
但我还是得到了同样的例外我对使用其他中介的解决方案持开放态度,但希望不必编写自定义中介来判断空值.