I am trying to test a simple JSON structure using Jackson, where I store the JSON request as a string in the dataJson variable.
public void unmarshal(InputStream is) throws Exception {
String dataJson= StUtil.toString(is);
System.out.println(dataJson);
String response = objectMapper.readValue(dataJson, String.class);
System.out.println(response);
}
SUtil.toString (InputStream) Method:
public static String toString(final InputStream is) {
final BufferedReader br = new BufferedReader(new InputStreamReader(is));
final StringBuffer buffer = new StringBuffer();
try {
for (String line; (line = br.readLine()) != null; ) {
buffer.append(line);
}
} catch (IOException ioe) {
}
return buffer.toString();
}
I am studying the check part with Jackson, but it throws an error / exception in the line
String response = objectMapper.readValue(dataJson, String.class);
And below is the exception that I get -
Exception: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token"
I wanted to know what I was doing wrong. Any help on this would be appreciated.
JSON request:
{"username" : "my_username","password" : "my_password","validation-factors":{"validationFactors":[{"name":"remote_address","value":"127.0.0.1"}]}}
source
share