mule json payload到db值从REST返回null

时间:2014-12-04 02:41:09

标签: mule

我的骡子流:

 <flow name="classmappingFlow1" doc:name="classmappingFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="${hostname}" port="${port}" path="insertClass" connector-ref="ConnectorWithoutMuleSession" doc:name="HTTP"/>
        <jersey:resources doc:name="REST">
            <component class="com.mycompany.mulesoft.rest.AccountMappingService"/>
        </jersey:resources>
        <json:json-to-object-transformer doc:name="JSON to Object"/>
        <logger message="Payload======#[payload]" level="INFO" doc:name="Logger"/>
        <logger message="=====Company===#[payload.Company]" level="INFO" doc:name="Logger"/>
        <db:insert config-ref="Oracle_Configuration" doc:name="Database">
            <db:parameterized-query><![CDATA[insert into SIAS_CONFIGURATION values(1, 1,1234,#[payload.Company],'Y','N','Y','you',sysdate,'you',sysdate)]]></db:parameterized-query>
        </db:insert>
    </flow>

控制台:

Payload======[{"Company":"KLM","Class":"Y","Location":"N","Department":"Y","EmplId":"1234"}]
=====Company===null

JSON数据:

[
 {
 "Company":"KLM",
 "Class":"Y",
 "Location":"N",
 "Department":"Y",
 "EmplId":"1234"
 }
]

休息组件:

@POST
@Path("/setClass")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String classSettings(@Payload String content){
    return content;
}

问题:我收到空值,没有数据(空)插入到数据库

1 个答案:

答案 0 :(得分:1)

jersey:resources 之后的returnClass="java.util.List"中使用json:json-to-object-transformer,如下所示: -

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