Json 对象和 Mule 表达式

Json to object and Mule expression

我有一个 json 文件,其中 link 是 https://gist.githubusercontent.com/Rajeun/b550fe17181610f5c0f0/raw/7ba82c6c1135d474e0bedc8b203d3cf16e196038/file.json

我想对布尔值 "sent" 做一个测试。有我的 xml 文件。

<http:request-config name="HTTP_Request_Configuration"
        host="gist.githubusercontent.com" port="443" protocol="HTTPS"
        doc:name="HTTP Request Configuration" />

    <flow name="testFlow">
        <poll doc:name="Poll">
            <http:request config-ref="HTTP_Request_Configuration"
                path="Rajeun/b550fe17181610f5c0f0/raw/7ba82c6c1135d474e0bedc8b203d3cf16e196038/file.json"
                method="GET" doc:name="HTTP" />
        </poll>



        <json:json-to-object-transformer
            returnClass="java.lang.Object" doc:name="JSON to Object" />
        <choice doc:name="Choice">
            <when expression="#[payload.sent] == true )">
                <logger message="its ok" level="INFO" doc:name="Logger"/>
            </when>
            <otherwise>
                <logger message="Error" level="INFO" doc:name="Logger"/>
            </otherwise>
        </choice>
    </flow> 

错误:

ERROR 2015-03-25 16:29:59,871 [[push1].testFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to transform from "json" to "java.lang.Object"
Code                  : MULE_ERROR-109
--------------------------------------------------------------------------------
Exception stack is:
1. Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
 at [Source: java.io.InputStreamReader@1a09a5b; line: 5, column: 4] (org.codehaus.jackson.JsonParseException)
  org.codehaus.jackson.JsonParser:1433 (null)
2. Failed to transform from "json" to "java.lang.Object" (org.mule.api.transformer.TransformerException)
  org.mule.module.json.transformers.JsonToObject:132 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.codehaus.jackson.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
 at [Source: java.io.InputStreamReader@1a09a5b; line: 5, column: 4]
    at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
    at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
    at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

我不知道是什么问题,请大家帮忙!!

JSON 文件中 "email" 后没有逗号,因此转换失败,这就是错误消息的意思。我相信正确的格式是

{
  "token" : 123,
  "tel" : 456,
  "email" : "Rm9vYmFyIQ==",
  "sent" : true
}

表达式应该是 <when expression="#[payload.sent == true ]">,这对我有用..

同样如 afelisatti 所述,email 属性后应有逗号 JSON payload

删除

<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />

并使用基于 json 的 mule 表达式 #[json:sent]