Skip to content

Commit 22b13b8

Browse files
authored
Support for application/json-patch+json media type (#9684)
1 parent c7c8dd8 commit 22b13b8

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

common/media-type/src/main/java/io/helidon/common/media/type/MediaTypeEnum.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ enum MediaTypeEnum implements MediaType {
2626
APPLICATION_XHTML_XML("application", "xhtml+xml"),
2727
APPLICATION_SVG_XML("application", "svg+xml"),
2828
APPLICATION_JSON("application", "json"),
29+
APPLICATION_JSON_PATCH_JSON("application", "json-patch+json"),
2930
APPLICATION_STREAM_JSON("application", "stream+json"),
3031
APPLICATION_FORM_URLENCODED("application", "x-www-form-urlencoded"),
3132
MULTIPART_FORM_DATA("multipart", "form-data"),

common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2019, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,6 +54,10 @@ public final class MediaTypes {
5454
* {@code application/json} media type.
5555
*/
5656
public static final MediaType APPLICATION_JSON = MediaTypeEnum.APPLICATION_JSON;
57+
/**
58+
* {@code application/json-patch+json} media type.
59+
*/
60+
public static final MediaType APPLICATION_JSON_PATCH_JSON = MediaTypeEnum.APPLICATION_JSON_PATCH_JSON;
5761
/**
5862
* {@code application/stream+json} media type.
5963
*/

http/media/jsonp/src/main/java/io/helidon/http/media/jsonp/JsonpSupport.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -128,7 +128,7 @@ public String type() {
128128
public <T> ReaderResponse<T> reader(GenericType<T> type, Headers requestHeaders) {
129129
if (isSupportedType(type)) {
130130
if (requestHeaders.contentType()
131-
.map(it -> it.test(MediaTypes.APPLICATION_JSON))
131+
.map(this::isMediaTypeSupported)
132132
.orElse(true)) {
133133
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
134134
}
@@ -159,7 +159,7 @@ public <T> ReaderResponse<T> reader(GenericType<T> type,
159159
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
160160
}
161161
for (HttpMediaType acceptedType : acceptedTypes) {
162-
if (acceptedType.test(MediaTypes.APPLICATION_JSON)) {
162+
if (isMediaTypeSupported(acceptedType)) {
163163
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
164164
}
165165
}
@@ -182,6 +182,11 @@ boolean isSupportedType(GenericType<?> type) {
182182
return JsonStructure.class.isAssignableFrom(type.rawType());
183183
}
184184

185+
boolean isMediaTypeSupported(HttpMediaType mediaType) {
186+
return mediaType.test(MediaTypes.APPLICATION_JSON)
187+
|| mediaType.test(MediaTypes.APPLICATION_JSON_PATCH_JSON);
188+
}
189+
185190
<T> EntityReader<T> reader() {
186191
return reader;
187192
}

0 commit comments

Comments
 (0)