Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Add this:</p> <pre><code>objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); </code></pre> <p>And make out of the deserialized exception the same way, as for the first time:</p> <pre><code>System.out.println( objectMapper.writeValueAsString( throwable ) ); </code></pre> <hr> <p>I used the following code:</p> <pre><code>public static void main( String[] args ) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure( SerializationFeature.INDENT_OUTPUT, true ); objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.setVisibility( PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY ); objectMapper.enableDefaultTyping( ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY ); try { Integer.parseInt( "String" ); } catch( NumberFormatException e ) { Throwable throwable = objectMapper.readValue( objectMapper.writeValueAsString( e ), Throwable.class ); System.out.println( objectMapper.writeValueAsString( throwable ) ); } } </code></pre> <p>Added this jars: jackson-annotations-2.2.0.jar, jackson-core-2.2.0.jar and jackson-databind-2.2.0.jar. </p> <p>After execution, the following is printed:</p> <pre><code>{ "@class" : "java.lang.NumberFormatException", "detailMessage" : "For input string: \"String\"", "cause" : null, "stackTrace" : [ { "declaringClass" : "java.lang.NumberFormatException", "methodName" : "forInputString", "fileName" : "NumberFormatException.java", "lineNumber" : 48, "className" : "java.lang.NumberFormatException", "nativeMethod" : false }, { "declaringClass" : "java.lang.Integer", "methodName" : "parseInt", "fileName" : "Integer.java", "lineNumber" : 449, "className" : "java.lang.Integer", "nativeMethod" : false }, { "declaringClass" : "java.lang.Integer", "methodName" : "parseInt", "fileName" : "Integer.java", "lineNumber" : 499, "className" : "java.lang.Integer", "nativeMethod" : false }, { "declaringClass" : "com.sample.bla.Main", "methodName" : "main", "fileName" : "Main.java", "lineNumber" : 24, "className" : "com.sample.bla.Main", "nativeMethod" : false }, { "declaringClass" : "sun.reflect.NativeMethodAccessorImpl", "methodName" : "invoke0", "fileName" : "NativeMethodAccessorImpl.java", "lineNumber" : -2, "className" : "sun.reflect.NativeMethodAccessorImpl", "nativeMethod" : true }, { "declaringClass" : "sun.reflect.NativeMethodAccessorImpl", "methodName" : "invoke", "fileName" : "NativeMethodAccessorImpl.java", "lineNumber" : 39, "className" : "sun.reflect.NativeMethodAccessorImpl", "nativeMethod" : false }, { "declaringClass" : "sun.reflect.DelegatingMethodAccessorImpl", "methodName" : "invoke", "fileName" : "DelegatingMethodAccessorImpl.java", "lineNumber" : 25, "className" : "sun.reflect.DelegatingMethodAccessorImpl", "nativeMethod" : false }, { "declaringClass" : "java.lang.reflect.Method", "methodName" : "invoke", "fileName" : "Method.java", "lineNumber" : 597, "className" : "java.lang.reflect.Method", "nativeMethod" : false }, { "declaringClass" : "com.intellij.rt.execution.application.AppMain", "methodName" : "main", "fileName" : "AppMain.java", "lineNumber" : 120, "className" : "com.intellij.rt.execution.application.AppMain", "nativeMethod" : false } ], "message" : "For input string: \"String\"", "localizedMessage" : "For input string: \"String\"" } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload