title: Serialize custom exception to JSON, not all fields are serialized
body: <p>I'm trying to serialize a custom Exception in Java using writeValueAsString() method from Jackson library. I intend to send it by HTTP to another machine. This is working partialy because not all fields are included in JSON after serialize. The top level exception Throwable implements Serializable interface, and also has some constructors that add info about what is to be serialized. I suppose the truth is somewhere here. Please help with some advices. Here is my custom exception code:</p>
  
  <pre><code>import java.io.Serializable;
  
  public class MyException extends RuntimeException{
  
  private static String type = null;
  private static String severity = null;
  
  // somewhere on google I red that should use setters to make serialize work
  
  public static void setType(String type) {
      MyException.type = type;
  }
  
  public static void setSeverity(String severity) {
      MyException.severity = severity;
  }
  
  public MyException(String message) {
      super(message);
  }
  }
  </code></pre>
  
  <p>somewhere in code I use:</p>
  
  <pre><code>MyException exc = new MyException("Here goes my exception.");
  MyException.setType(exc.getClass().getSimpleName());    
  MyException.setSeverity("Major");
  throw exc;
  </code></pre>
  
  <p>and in other place I have:</p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  try {   
       responseBuilder.entity(mapper.writeValueAsString(MyException) );
  } 
  catch (JsonGenerationException e) {e.printStackTrace(); } 
  catch (JsonMappingException e) {e.printStackTrace(); } 
  catch (IOException e) { e.printStackTrace(); }
  </code></pre>
  
  <p>The result JSON object is:</p>
  
  <pre><code>{"cause":null,"message":"Here goes my exception.","localizedMessage":"Here goes my exception.","stackTrace":[{...a usual stack trace...}]}
  </code></pre>
  
  <p>Here I also expect to see my type and severity fields.</p>