我有这个json对象
data = {
"amount": "70",
"cardNumber": "4222222222222",
"expiryDate": "1215",
"currency": "Currency.ISK.alpha"
}我想把这个json对象改成java组件,用java调用各种java函数。我在把这个json对象转换成java组件时遇到了问题。我已经创建了以下两个java类。
@JsonAutoDetect
public class Handpoint {
private String amount;
private String cardNumber;
private String expireDate;
private String currency;
public String getAmount() { return amount; }
public void setAmount(String amount) { this.amount = amount; }
public String getCardNumber() { return cardNumber; }
public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; }
public String getExpireDate() { return expireDate; }
public void setExpireDate(String expireDate) { this.expireDate = expireDate; }
public String getCurrency() { return currency; }
public void setCurrency(String currency) { this.currency = currency; }}
和
public class HandpointService {
public void ProcessPerson(@Payload Handpoint handpoint) {
String cardNumber = handpoint.getCardNumber();
cardNumber.toString();
}
}配置文件很简单
<flow name="json_to_java_componentFlow1" doc:name="json_to_java_componentFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="json" doc:name="HTTP"/>
<component class="is.threesixtyfive.example.HandpointService" doc:name="Java"/>
</flow>当我运行此命令时,我得到以下错误:
Message : Failed to transform from "json" to
"is.threesixtyfive.example.Handpoint"
Code : MULE_ERROR-109
--------------------------------------------------------------------------------
Exception stack is:
1. Unrecognized field "expiryDate" (Class is.threesixtyfive.example.Handpoint), not marked as ignorable
at [Source: java.io.InputStreamReader@26940a2e; line: 1, column: 98] (through reference chain: is.threesixtyfive.example.Handpoint["expiryDate"]) (org.codehaus.jackson.map.exc.UnrecognizedPropertyException)
org.codehaus.jackson.map.exc.UnrecognizedPropertyException:53 (null)
2. Failed to transform from "json" to "is.threesixtyfive.example.Handpoint" (org.mule.api.transformer.TransformerException)
org.mule.module.json.transformers.JsonToObject:136 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "expiryDate" (Class is.threesixtyfive.example.Handpoint), not marked as ignorable
at [Source: java.io.InputStreamReader@26940a2e; line: 1, column: 98] (through reference chain: is.threesixtyfive.example.Handpoint["expiryDate"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************任何帮助都将不胜感激
发布于 2013-06-15 03:45:05
问题来自于这样一个事实:
request-response,因此它将向调用者返回响应,Mule使用组件之后的当前消息有效负载-可能是使用的输入流-为入站端点创建响应,但失败了。
如果我添加:
<set-payload value="foo" />在组件之后,错误就会清除( HTTP客户端收到"foo")。
发布于 2013-06-14 21:10:53
JSON和POJO的字段名不同。
在JSON中:expiryDate
在POJO中:expireDate
发布于 2014-12-19 17:51:01
我认为这样做的一种方法是首先处理转换部分,使用transformer JSON to Object并加载映射引用,然后使用Java组件并加载HandpointService类并使其可调用,这样您就可以拥有类的入口点。
https://stackoverflow.com/questions/17108588
复制相似问题