Need to insert json data from java rest Client

105 views
Skip to first unread message

Arnab Ganguly

unread,
Apr 23, 2014, 8:34:03 AM4/23/14
to virgil...@googlegroups.com

Hi

  I want to insert json data using simple REST Client. -d option of curl command does not work in REST Client.

My java code as below.


DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPut putRequest = new HttpPut(
                    "http://localhost:8080/virgil/data/ericsson/emp/666?index=true");

            StringEntity inputEntity = new StringEntity("- d"+"{\"empname\":\"PriyaDarshini\",\"address\":\"Noida-126\",\"dob\":\"10-8-1987\","
                    + "\"designation\":\"Solution Integrator\",\"about\":\"Works for AT&T.\n. Currenly in sprintteam2.She likes to play cricket, .\"}");
            inputEntity.setContentType("application/json");
            putRequest.setEntity(inputEntity);

            HttpResponse response = httpClient.execute(putRequest);


and getting exception in virgil

----------------------------------------------------------------ERROR [2014-04-23 12:13:33,321] com.yammer.dropwizard.jersey.LoggingExceptionMapper: Error handling a request: 1f5bff27e96fa836
! org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
!  at [Source: org.eclipse.jetty.server.HttpInput@113f3c3e; line: 1, column: 1]
!     at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
!     at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
!     at org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:44)
!     at org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:13)
!     at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2725)
!     at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1916)
!     at com.yammer.dropwizard.json.Json.read(Json.java:111)
!     at com.yammer.dropwizard.jersey.JacksonMessageBodyProvider.readFrom(JacksonMessageBodyProvider.java:72)
!     at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
!     at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
!     at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
!     at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
!     at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$VoidOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:166)
!     at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
!     at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)


Brian O'Neill

unread,
Apr 23, 2014, 4:04:23 PM4/23/14
to virgil...@googlegroups.com
I believe the newer version of DropWizard attempts to parse the JSON when the json content type is provided.  The stack is coming from dropwizard itself.

Can you try the same request without setting the content-type header?

-brian

---
Brian O'Neill
Chief Technology Officer

Health Market Science
The Science of Better Results
2700 Horizon Drive  King of Prussia, PA  19406

This information transmitted in this email message is for the intended recipient only and may contain confidential and/or privileged material. If you received this email in error and are not the intended recipient, or the person responsible to deliver it to the intended recipient, please contact the sender at the email above and delete this email and any attachments and destroy any copies thereof. Any review, retransmission, dissemination, copying or other use of, or taking any action in reliance upon, this information by persons or entities other than the intended recipient is strictly prohibited.

--
You received this message because you are subscribed to the Google Groups "virgil-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to virgil-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages