Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes around default JSON handling #13886

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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