這裏是我的供應商:如何JSON在POST轉換與JavaBean
class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"
,這裏是我的javaBean
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;
@JsonRootName("issue")
public class TestBean {
@JsonProperty("project_id")
private Integer projectId;
@JsonProperty("subject")
private String subject;
public Integer getProjectId() {
return projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
}
這裏是我的服務
@WebService
public class IssueRestfulApi {
@POST
@Path("/create")
@Consumes(value = {MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public void createIssue(TestBean bean) {
System.out.println(bean.getSubject());
System.out.println("get create request");
}
}
然後我發送POST請求像這樣:
{"issue": {
"project_id": 1,
"subject": "Example"
}
}
最後我得到這個異常:
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "issue" (Class com.rakuten.tranp.api.bean.TestBean), not marked as ignorable
at [Source: [email protected]; line: 1, column: 12] (through reference chain: com.rakuten.tranp.api.bean.TestBean["issue"])
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)
at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1311)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1262)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:801)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:764)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:212)
... 28 more
如何解決這個問題,請幫幫我,謝謝 你的每一個不多, regurd。
是你使用彈簧? –
是的,我在我的模塊中使用彈簧 –