diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/WebApplicationException.java b/jaxrs-api/src/main/java/jakarta/ws/rs/WebApplicationException.java index 6ac070c25..aeb3322b3 100644 --- a/jaxrs-api/src/main/java/jakarta/ws/rs/WebApplicationException.java +++ b/jaxrs-api/src/main/java/jakarta/ws/rs/WebApplicationException.java @@ -32,7 +32,7 @@ public class WebApplicationException extends RuntimeException { private static final long serialVersionUID = 8273970399584007146L; - private final Response response; + private final transient Response response; /** * Construct a new instance with a default HTTP status code of 500 and a default message generated from the HTTP status diff --git a/jaxrs-api/src/test/java/jakarta/ws/rs/SerializationTest.java b/jaxrs-api/src/test/java/jakarta/ws/rs/SerializationTest.java new file mode 100644 index 000000000..7ec81fc92 --- /dev/null +++ b/jaxrs-api/src/test/java/jakarta/ws/rs/SerializationTest.java @@ -0,0 +1,173 @@ +package jakarta.ws.rs; + +import jakarta.ws.rs.core.EntityTag; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.Link; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.NewCookie; +import jakarta.ws.rs.core.Response; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.lang.annotation.Annotation; +import java.net.URI; +import java.util.Date; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import org.junit.Test; + +public class SerializationTest { + + class TestResponse extends Response { + + @Override + public int getStatus() { + return 0; + } + + @Override + public StatusType getStatusInfo() { + return null; + } + + @Override + public Object getEntity() { + return null; + } + + @Override + public T readEntity(Class entityType) { + return null; + } + + @Override + public T readEntity(GenericType entityType) { + return null; + } + + @Override + public T readEntity(Class entityType, Annotation[] annotations) { + return null; + } + + @Override + public T readEntity(GenericType entityType, Annotation[] annotations) { + return null; + } + + @Override + public boolean hasEntity() { + return false; + } + + @Override + public boolean bufferEntity() { + return false; + } + + @Override + public void close() { + + } + + @Override + public MediaType getMediaType() { + return null; + } + + @Override + public Locale getLanguage() { + return null; + } + + @Override + public int getLength() { + return 0; + } + + @Override + public Set getAllowedMethods() { + return null; + } + + @Override + public Map getCookies() { + return null; + } + + @Override + public EntityTag getEntityTag() { + return null; + } + + @Override + public Date getDate() { + return null; + } + + @Override + public Date getLastModified() { + return null; + } + + @Override + public URI getLocation() { + return null; + } + + @Override + public Set getLinks() { + return null; + } + + @Override + public boolean hasLink(String relation) { + return false; + } + + @Override + public Link getLink(String relation) { + return null; + } + + @Override + public Link.Builder getLinkBuilder(String relation) { + return null; + } + + @Override + public MultivaluedMap getMetadata() { + return null; + } + + @Override + public MultivaluedMap getStringHeaders() { + return null; + } + + @Override + public String getHeaderString(String name) { + return null; + } + } + + @Test + public void testSerializaWebApplicationException() throws Exception { + final WebApplicationException exceptionWithResponse = new WebApplicationException("message", new RuntimeException("cause"), new TestResponse()); + serialize(exceptionWithResponse); + + } + + private void serialize(WebApplicationException exception) throws IOException { + try ( + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + ) { + oos.writeObject(exception); + oos.flush(); + byte[] data = bos.toByteArray(); + } + } +}