I m trying to Map and Send a JSON to a Java Object for Rest Web Service . I m using a RESTful WS with Jersey Java.
I am new to this REST, If am not sending correctly please correct me.
** Here Is a example of My JSON:
MY Json Input in Google Rest Plugin as Raw data is :** as below
JSON Input : I need to Map it to : com.cordys.entity.bean.ClaimTask claimTaskObj
{"taskId":["002481F0-8E9F-11E3-FB97-B80661C15631","002481F0-8E9F-11E3-FB97-B80661C15635"]}
================================================================================= I got Below error :
So every time i send this request the following error appears:
com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "taskId" (Class com.business.entity.bean.ClaimTask), not marked as ignorable at [Source: org.apache.catalina.connector.CoyoteInputStream@409b5f9c; line: 1, column: 12] (through reference chain: com.business.entity.bean.ClaimTask["taskId"]) 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.jac kson.map.ObjectMapper.readValue(ObjectMapper.java:1315) at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419) at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139) at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:488) at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjecta
================================================================================= My Rest Web service Method is :
My Rest Service Method.
@POST
@ApiResponses(value = {
@ApiResponse(code = 200, message = STATUS_200),
@ApiResponse(code = 500, message = STATUS_500)
})
@Path("/claimTaskObj")
@Consumes({ "application/json", "application/xml"})
@Produces({ "application/json", "application/javascript", "application/xml" })
public Response claimTaskObj(
com.business.entity.bean.ClaimTask claimTaskObj,
@HeaderParam("SAMLart") String samlArt,
@HeaderParam("otdsticket") String oTAuthenticationHeader,
@Context UriInfo uriInfo) {
System.out.println("TaskService.claimTask()====== IN");
// Integration with JAXWS
//System.out.println("oTAuthenticationHeader ="+oTAuthenticationHeader);
ClaimTaskJaxWsClient claimTaskClient = new ClaimTaskJaxWsClient();
ClaimTaskResponse jaxWSResponse = null;
MultivaluedMap<String, String> inputParameters = uriInfo.getQueryParameters();
inputParameters.add("task_id", claimTaskObj.getTaskId().get(0));
String callback = inputParameters.getFirst("callback");
try {
jaxWSResponse = claimTaskClient.executeSoapRequest(inputParameters, samlArt,oTAuthenticationHeader);
return Util.getRespone(jaxWSResponse, callback, 200);
} catch (com.business.jaxws.task.claimtask.businessFaultDetail e) {
return Util.getRespone(e.getFaultInfo(), callback, 500);
}
MY Jaxbi Class is :
package com.business.entity.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "taskIdObj", propOrder = {
"taskId"
})
@XmlRootElement(name = "ClaimTask", namespace = "http://schemas.business.com/notification/workflow/1.0")
public class ClaimTask implements Serializable {
@XmlElement(name = "TaskId", namespace = "http://schemas.business.com/notification/workflow/1.0", required = true)
protected List<String> taskId;
public List<String> getTaskId() {
if (taskId == null) {
taskId = new ArrayList<String>();
}
return this.taskId;
}
public void setTaskId(String task_Id) {
if (this.taskId == null) {
this.taskId = new ArrayList<String>();
}
this.taskId.add(task_Id);
}
public void setTaskId(List<String> task_Id) {
if (this.taskId == null) {
this.taskId = new ArrayList<String>();
}
this.taskId.addAll(task_Id);
}
}
you can solve and test your web services by implementing following code
ClaimTask claim = new com.howtodoinjava.model.ClaimTask();
claim.setTaskId("002481F0-8E9F-11E3-FB97-B80661C15631");
claim.setTaskId("002481F0-8E9F-11E3-FB97-B80661C15635");
StringWriter writer = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(ClaimTask.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.marshal(claim, writer);
DefaultHttpClient httpClient = new DefaultHttpClient();
// Define a postRequest request
HttpPost postRequest = new HttpPost(
"http://localhost:8090/BPMService/v1/tasks/claimTaskObj");
// Set the API media type in http content-type header
postRequest.addHeader("SAMLart","XXXXXX");
postRequest.addHeader("otdsticket","YYYYYYYYYYYYY");
postRequest.addHeader("content-type", "application/xml");
// Set the request post body
StringEntity userEntity = new StringEntity(writer.getBuffer().toString());
postRequest.setEntity(userEntity);
// Send the request; It will immediately return the response in
// HttpResponse object if any
HttpResponse response = httpClient.execute(postRequest);
// verify the valid error code first
int statusCode = response.getStatusLine().getStatusCode();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.