Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is known that any Exception/Throwable class can not be marshalled by JAXB due to the fact that StackTrace does not have a default constructor. What you can do is create your own Exception class that extends from say in your example, WebServiceException. In your class, override the methods that would use StackTrace and add the <code>@XmlTransient</code> annotation to them. As long as you are using JAXB 2.2.4u2+ the Marshaller will obey the <code>@XmlTrasient</code> annotation in your custom class. </p> <p>Additional detail is available at <a href="http://java.net/jira/browse/JAXB-814" rel="nofollow">http://java.net/jira/browse/JAXB-814</a> that outlines the defect where <code>@XmlTransient</code> didn't work well on subclasses.</p> <p>Below is a sample class that will marshall properly:</p> <pre><code>package com.stackoverflow.7232331; import javax.ws.rs.core.Response.Status; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; @XmlRootElement public class CustomException extends RuntimeException { /** * */ private static final long serialVersionUID = -672804070691541883L; protected String reason; protected Status status; protected int errorCode; public String getReason() { return reason; } public void setReason(String reason) { this.reason = reason; } public Status getStatus() { return status; } public void setStatus(Status status) { this.status = status; } public int getErrorCode() { return errorCode; } public void setErrorCode(int errorCode) { this.errorCode = errorCode; } public CustomException(Status status, String message, String reason, int errorCode) { super(message); this.reason = reason; this.status = status; this.errorCode = errorCode; } public CustomException() { super(); } @XmlTransient @Override public StackTraceElement[] getStackTrace() { return super.getStackTrace(); } @XmlTransient @Override public Throwable getCause() { return super.getCause(); } } </code></pre> <p>If you use Maven, you'll need this dependency:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt; &lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt; &lt;version&gt;2.2.5&lt;/version&gt; &lt;/dependency&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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