Skip to content

Commit

Permalink
Merge pull request #13886 from stuartwdouglas/default-json-fix
Browse files Browse the repository at this point in the history
Fixes around default JSON handling
  • Loading branch information
gsmet authored Dec 15, 2020
2 parents 5f19ece + e481ab4 commit f3cf904
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat
return false;
}
return mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)
|| mediaType.isWildcardType()
|| super.isWriteable(type, genericType, annotations, mediaType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat
if (BUILTIN_DEFAULTS.contains(type)) {
return false;
}
return isSupportedMediaType(mediaType) || mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE);
return isSupportedMediaType(mediaType) || mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)
|| mediaType.isWildcardType();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.inject.Inject;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

Expand Down Expand Up @@ -46,6 +47,7 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat
@Override
public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
if (o instanceof String) { // YUK: done in order to avoid adding extra quotes...
entityStream.write(((String) o).getBytes());
} else {
Expand All @@ -60,6 +62,7 @@ public boolean isWriteable(Class<?> type, ResteasyReactiveResourceInfo target, M

@Override
public void writeResponse(Object o, ServerRequestContext context) throws WebApplicationException, IOException {
context.serverResponse().setResponseHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
OutputStream stream = context.getOrCreateOutputStream();
if (o instanceof String) { // YUK: done in order to avoid adding extra quotes...
stream.write(((String) o).getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.inject.Inject;
import javax.json.bind.Jsonb;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

Expand All @@ -32,6 +33,7 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat
@Override
public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
if (o instanceof String) { // YUK: done in order to avoid adding extra quotes...
entityStream.write(((String) o).getBytes());
} else {
Expand All @@ -46,6 +48,7 @@ public boolean isWriteable(Class<?> type, ResteasyReactiveResourceInfo target, M

@Override
public void writeResponse(Object o, ServerRequestContext context) throws WebApplicationException, IOException {
context.serverResponse().setResponseHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
OutputStream originalStream = context.getOrCreateOutputStream();
OutputStream stream = new NoopCloseAndFlushOutputStream(originalStream);
if (o instanceof String) { // YUK: done in order to avoid adding extra quotes...
Expand Down

0 comments on commit f3cf904

Please sign in to comment.