Saturday 15 May 2010

java - org.codehaus.jackson.map.JsonMappingException using ObjectMapper -


I am trying to call my REST service using an object mapper.

  url = new URL ("http://phx5qa01c-8539.host.com:8080/bservice/BService/v1/getSimpleString"); String str = mapper.readValue (url, String.class);   

and the URL will give me this string back -

{attributes: [{nm: "sellers2" vt: "java.util.Map" status "Success": jsonValue: "{vv": {"regSiteId": null, "userstate": null, "userId": 609}, "cn": 1}], "LMD": 20130206211109} "}]} < / P>

When I'm trying that URL on the browser, I am withdrawing the string above. But as soon as I do the same thing in code I am getting this exception -

org.codehaus.jackson.map.JsonMappingException: can not deserialize the example of java.lang.START_OBJECTBen from the token

Trying to deserialize Jackson, your JSON as a new string object, but can not find the attribute eg a method String.setAttributes (). Any deserialisation For errors, 'these are to be taken out of the START_OBJECT token'; there is more information under the stack trace. TI.

Try:

  Map myMap = Mapper.readValue (url, Map.class);   

Or if you really want a string, do not use Jackson to read the URL in the string using standard Java code:

  String str = IOUtils.toString (url);    

No comments:

Post a Comment