我有这个 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)
********************************************************************************
任何帮助,将不胜感激