Skip to content

Commit

Permalink
Support for application/json-patch+json media type (#9684)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvallin authored Jan 27, 2025
1 parent c7c8dd8 commit 22b13b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@ enum MediaTypeEnum implements MediaType {
APPLICATION_XHTML_XML("application", "xhtml+xml"),
APPLICATION_SVG_XML("application", "svg+xml"),
APPLICATION_JSON("application", "json"),
APPLICATION_JSON_PATCH_JSON("application", "json-patch+json"),
APPLICATION_STREAM_JSON("application", "stream+json"),
APPLICATION_FORM_URLENCODED("application", "x-www-form-urlencoded"),
MULTIPART_FORM_DATA("multipart", "form-data"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
* Copyright (c) 2019, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,10 @@ public final class MediaTypes {
* {@code application/json} media type.
*/
public static final MediaType APPLICATION_JSON = MediaTypeEnum.APPLICATION_JSON;
/**
* {@code application/json-patch+json} media type.
*/
public static final MediaType APPLICATION_JSON_PATCH_JSON = MediaTypeEnum.APPLICATION_JSON_PATCH_JSON;
/**
* {@code application/stream+json} media type.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -128,7 +128,7 @@ public String type() {
public <T> ReaderResponse<T> reader(GenericType<T> type, Headers requestHeaders) {
if (isSupportedType(type)) {
if (requestHeaders.contentType()
.map(it -> it.test(MediaTypes.APPLICATION_JSON))
.map(this::isMediaTypeSupported)
.orElse(true)) {
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public <T> ReaderResponse<T> reader(GenericType<T> type,
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
}
for (HttpMediaType acceptedType : acceptedTypes) {
if (acceptedType.test(MediaTypes.APPLICATION_JSON)) {
if (isMediaTypeSupported(acceptedType)) {
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
}
}
Expand All @@ -182,6 +182,11 @@ boolean isSupportedType(GenericType<?> type) {
return JsonStructure.class.isAssignableFrom(type.rawType());
}

boolean isMediaTypeSupported(HttpMediaType mediaType) {
return mediaType.test(MediaTypes.APPLICATION_JSON)
|| mediaType.test(MediaTypes.APPLICATION_JSON_PATCH_JSON);
}

<T> EntityReader<T> reader() {
return reader;
}
Expand Down

0 comments on commit 22b13b8

Please sign in to comment.