Skip to content

Commit e254ae8

Browse files
committed
Allow to disable JSON-B by a property
Signed-off-by: jansupol <[email protected]>
1 parent 88ebd40 commit e254ae8

File tree

7 files changed

+185
-12
lines changed

7 files changed

+185
-12
lines changed

core-client/src/main/java/org/glassfish/jersey/client/ClientProperties.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,34 @@ public final class ClientProperties {
240240
@PropertyAlias
241241
public static final String OUTBOUND_CONTENT_LENGTH_BUFFER = CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER_CLIENT;
242242

243+
/**
244+
* If {@code true} then disable configuration of Json Binding (JSR-367)
245+
* feature on client.
246+
* <p>
247+
* By default, Json Binding on client is automatically enabled if global
248+
* property
249+
* {@value org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE}
250+
* is not disabled. If set then the client property value overrides the
251+
* global property value.
252+
* <p>
253+
* The default value is {@code false}.
254+
* </p>
255+
* <p>
256+
* The name of the configuration property is <tt>{@value}</tt>.
257+
* </p>
258+
* <p>This constant is an alias for {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE_CLIENT}.</p>
259+
*
260+
* @see org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE
261+
* @since 2.45
262+
*/
263+
@PropertyAlias
264+
public static final String JSON_BINDING_FEATURE_DISABLE = CommonProperties.JSON_BINDING_FEATURE_DISABLE_CLIENT;
265+
243266
/**
244267
* If {@code true} then disable configuration of Json Processing (JSR-353)
245268
* feature on client.
246269
* <p>
247-
* By default Json Processing on client is automatically enabled if global
270+
* By default, Json Processing on client is automatically enabled if global
248271
* property
249272
* {@value org.glassfish.jersey.CommonProperties#JSON_PROCESSING_FEATURE_DISABLE}
250273
* is not disabled. If set then the client property value overrides the
@@ -265,7 +288,7 @@ public final class ClientProperties {
265288
/**
266289
* If {@code true} then disable META-INF/services lookup on client.
267290
* <p>
268-
* By default Jersey looks up SPI implementations described by {@code META-INF/services/*} files.
291+
* By default, Jersey looks up SPI implementations described by {@code META-INF/services/*} files.
269292
* Then you can register appropriate provider classes by {@link javax.ws.rs.core.Application}.
270293
* </p>
271294
* <p>

core-common/src/main/java/org/glassfish/jersey/CommonProperties.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public final class CommonProperties {
7171
/**
7272
* If {@code true} then disable feature auto discovery globally on client/server.
7373
* <p>
74-
* By default auto discovery is automatically enabled. The value of this property may be overridden by the client/server
74+
* By default, auto discovery is automatically enabled. The value of this property may be overridden by the client/server
7575
* variant of this property.
7676
* <p>
7777
* The default value is {@code false}.
@@ -98,10 +98,42 @@ public final class CommonProperties {
9898
*/
9999
public static final String FEATURE_AUTO_DISCOVERY_DISABLE_SERVER = "jersey.config.server.disableAutoDiscovery";
100100

101+
102+
/**
103+
* If {@code true} then disable configuration of Json Binding (JSR-367) feature.
104+
* <p>
105+
* By default, Json Binding is automatically enabled. The value of this property may be overridden by the client/server
106+
* variant of this property.
107+
* <p>
108+
* The default value is {@code false}.
109+
* </p>
110+
* <p>
111+
* The name of the configuration property is <tt>{@value}</tt>.
112+
* </p>
113+
* @since 2.45
114+
*/
115+
public static final String JSON_BINDING_FEATURE_DISABLE = "jersey.config.disableJsonBinding";
116+
117+
/**
118+
* Client-specific version of {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE}.
119+
*
120+
* If present, it overrides the generic one for the client environment.
121+
* @since 2.45
122+
*/
123+
public static final String JSON_BINDING_FEATURE_DISABLE_CLIENT = "jersey.config.client.disableJsonBinding";
124+
125+
/**
126+
* Server-specific version of {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE}.
127+
*
128+
* If present, it overrides the generic one for the server environment.
129+
* @since 2.45
130+
*/
131+
public static final String JSON_BINDING_FEATURE_DISABLE_SERVER = "jersey.config.server.disableJsonBinding";
132+
101133
/**
102134
* If {@code true} then disable configuration of Json Processing (JSR-353) feature.
103135
* <p>
104-
* By default Json Processing is automatically enabled. The value of this property may be overridden by the client/server
136+
* By default, Json Processing is automatically enabled. The value of this property may be overridden by the client/server
105137
* variant of this property.
106138
* <p>
107139
* The default value is {@code false}.
@@ -131,7 +163,7 @@ public final class CommonProperties {
131163
/**
132164
* If {@code true} then disable META-INF/services lookup globally on client/server.
133165
* <p>
134-
* By default Jersey looks up SPI implementations described by META-INF/services/* files.
166+
* By default, Jersey looks up SPI implementations described by META-INF/services/* files.
135167
* Then you can register appropriate provider classes by {@link javax.ws.rs.core.Application}.
136168
* </p>
137169
* <p>
@@ -164,7 +196,7 @@ public final class CommonProperties {
164196
/**
165197
* If {@code true} then disable configuration of MOXy Json feature.
166198
* <p>
167-
* By default MOXy Json is automatically enabled. The value of this property may be overridden by the client/server
199+
* By default, MOXy Json is automatically enabled. The value of this property may be overridden by the client/server
168200
* variant of this property.
169201
* <p>
170202
* The default value is {@code false}.

core-server/src/main/java/org/glassfish/jersey/server/ServerProperties.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -302,7 +302,7 @@ public final class ServerProperties {
302302
/**
303303
* If {@code true} then disable auto discovery on server.
304304
*
305-
* By default auto discovery is automatically enabled if global property
305+
* By default, auto discovery is automatically enabled if global property
306306
* {@value org.glassfish.jersey.CommonProperties#FEATURE_AUTO_DISCOVERY_DISABLE} is not disabled. If set then the server
307307
* property value overrides the global property value.
308308
* <p>
@@ -342,10 +342,29 @@ public final class ServerProperties {
342342
@PropertyAlias
343343
public static final String OUTBOUND_CONTENT_LENGTH_BUFFER = CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER_SERVER;
344344

345+
/**
346+
* If {@code true} then disable configuration of Json Binding (JSR-367) feature on server.
347+
*
348+
* By default, Json Binding is automatically enabled if global property
349+
* {@value org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE} is not disabled. If set then the server
350+
* property value overrides the global property value.
351+
* <p>
352+
* The default value is {@code false}.
353+
* </p>
354+
* <p>
355+
* The name of the configuration property is <tt>{@value}</tt>.
356+
* </p>
357+
* <p>This constant is an alias for {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE_SERVER}</p>
358+
*
359+
* @see org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE
360+
*/
361+
@PropertyAlias
362+
public static final String JSON_BINDING_FEATURE_DISABLE = CommonProperties.JSON_BINDING_FEATURE_DISABLE_SERVER;
363+
345364
/**
346365
* If {@code true} then disable configuration of Json Processing (JSR-353) feature on server.
347366
*
348-
* By default Json Processing is automatically enabled if global property
367+
* By default, Json Processing is automatically enabled if global property
349368
* {@value org.glassfish.jersey.CommonProperties#JSON_PROCESSING_FEATURE_DISABLE} is not disabled. If set then the server
350369
* property value overrides the global property value.
351370
* <p>
@@ -364,7 +383,7 @@ public final class ServerProperties {
364383
/**
365384
* If {@code true} then disable META-INF/services lookup on server.
366385
*
367-
* By default Jersey looks up SPI implementations described by META-INF/services/* files.
386+
* By default, Jersey looks up SPI implementations described by META-INF/services/* files.
368387
* Then you can register appropriate provider classes by {@link javax.ws.rs.core.Application}.
369388
* <p>
370389
* The default value is {@code false}.
@@ -383,7 +402,7 @@ public final class ServerProperties {
383402
/**
384403
* If {@code true} then disable configuration of MOXy Json feature on server.
385404
*
386-
* By default MOXy Json is automatically enabled if global property
405+
* By default, MOXy Json is automatically enabled if global property
387406
* {@value org.glassfish.jersey.CommonProperties#MOXY_JSON_FEATURE_DISABLE} is not disabled. If set then the server
388407
* property value overrides the global property value.
389408
* <p>

docs/src/main/docbook/appendix-properties.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@
7171
</para>
7272
</entry>
7373
</row>
74+
<row>
75+
<entry>&jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE; /
76+
&jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE_CLIENT; /
77+
&jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE_SERVER;</entry>
78+
<entry><literal>jersey.config.disableJsonBinding</literal> /
79+
<literal>jersey.config.client.disableJsonBinding</literal> /
80+
<literal>jersey.config.server.disableJsonBinding</literal></entry>
81+
<entry>
82+
<para>
83+
Disables configuration of Json Binding (JSR-367) feature. Default value is <literal>false</literal>.
84+
</para>
85+
<para>
86+
Since 2.45.
87+
</para>
88+
</entry>
89+
</row>
7490
<row>
7591
<entry>&jersey.common.CommonProperties.JSON_PROCESSING_FEATURE_DISABLE; /
7692
&jersey.common.CommonProperties.JSON_PROCESSING_FEATURE_DISABLE_CLIENT; /
@@ -391,6 +407,15 @@
391407
</para>
392408
</entry>
393409
</row>
410+
<row>
411+
<entry>&jersey.server.ServerProperties.JSON_BINDING_FEATURE_DISABLE;</entry>
412+
<entry><literal>jersey.config.server.disableJsonBinding</literal></entry>
413+
<entry>
414+
<para>
415+
Disables configuration of Json Processing (JSR-353) feature. Default value is <literal>false</literal>.
416+
</para>
417+
</entry>
418+
</row>
394419
<row>
395420
<entry>&jersey.server.ServerProperties.JSON_PROCESSING_FEATURE_DISABLE;</entry>
396421
<entry><literal>jersey.config.server.disableJsonProcessing</literal></entry>
@@ -998,6 +1023,15 @@
9981023
</para>
9991024
</entry>
10001025
</row>
1026+
<row>
1027+
<entry>&jersey.client.ClientProperties.JSON_BINDING_FEATURE_DISABLE;</entry>
1028+
<entry><literal>jersey.config.client.disableJsonBinding</literal></entry>
1029+
<entry>
1030+
<para>
1031+
Disables configuration of Json Binding (JSR-367) feature. Default value is <literal>false</literal>.
1032+
</para>
1033+
</entry>
1034+
</row>
10011035
<row>
10021036
<entry>&jersey.client.ClientProperties.JSON_PROCESSING_FEATURE_DISABLE;</entry>
10031037
<entry><literal>jersey.config.client.disableJsonProcessing</literal></entry>

docs/src/main/docbook/jersey.ent

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@
344344
<!ENTITY jersey.client.ClientProperties.DEFAULT_CHUNK_SIZE "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#DEFAULT_CHUNK_SIZE'>ClientProperties.DEFAULT_CHUNK_SIZE</link>" >
345345
<!ENTITY jersey.client.ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#FEATURE_AUTO_DISCOVERY_DISABLE'>ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE</link>" >
346346
<!ENTITY jersey.client.ClientProperties.FOLLOW_REDIRECTS "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#FOLLOW_REDIRECTS'>ClientProperties.FOLLOW_REDIRECTS</link>" >
347+
<!ENTITY jersey.client.ClientProperties.JSON_BINDING_FEATURE_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#JSON_BINDING_FEATURE_DISABLE'>ClientProperties.JSON_BINDING_FEATURE_DISABLE</link>" >
347348
<!ENTITY jersey.client.ClientProperties.JSON_PROCESSING_FEATURE_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#JSON_PROCESSING_FEATURE_DISABLE'>ClientProperties.JSON_PROCESSING_FEATURE_DISABLE</link>" >
348349
<!ENTITY jersey.client.ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#METAINF_SERVICES_LOOKUP_DISABLE'>ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE</link>" >
349350
<!ENTITY jersey.client.ClientProperties.MOXY_JSON_FEATURE_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#MOXY_JSON_FEATURE_DISABLE'>ClientProperties.MOXY_JSON_FEATURE_DISABLE</link>" >
@@ -388,6 +389,9 @@
388389
<!ENTITY jersey.common.CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#FEATURE_AUTO_DISCOVERY_DISABLE'>CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE</link>" >
389390
<!ENTITY jersey.common.CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE_CLIENT "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#FEATURE_AUTO_DISCOVERY_DISABLE_CLIENT'>CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE_CLIENT</link>" >
390391
<!ENTITY jersey.common.CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE_SERVER "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#FEATURE_AUTO_DISCOVERY_DISABLE_SERVER'>CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE_SERVER</link>" >
392+
<!ENTITY jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#JSON_BINDING_FEATURE_DISABLE'>CommonProperties.JSON_BINDING_FEATURE_DISABLE</link>" >
393+
<!ENTITY jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE_CLIENT "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#JSON_BINDING_FEATURE_DISABLE_CLIENT'>CommonProperties.JSON_BINDING_FEATURE_DISABLE_CLIENT</link>" >
394+
<!ENTITY jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE_SERVER "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#JSON_BINDING_FEATURE_DISABLE_SERVER'>CommonProperties.JSON_BINDING_FEATURE_DISABLE_SERVER</link>" >
391395
<!ENTITY jersey.common.CommonProperties.JSON_PROCESSING_FEATURE_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#JSON_PROCESSING_FEATURE_DISABLE'>CommonProperties.JSON_PROCESSING_FEATURE_DISABLE</link>" >
392396
<!ENTITY jersey.common.CommonProperties.JSON_PROCESSING_FEATURE_DISABLE_CLIENT "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#JSON_PROCESSING_FEATURE_DISABLE_CLIENT'>CommonProperties.JSON_PROCESSING_FEATURE_DISABLE_CLIENT</link>" >
393397
<!ENTITY jersey.common.CommonProperties.JSON_PROCESSING_FEATURE_DISABLE_SERVER "<link xlink:href='&jersey.javadoc.uri.prefix;/CommonProperties.html#JSON_PROCESSING_FEATURE_DISABLE_SERVER'>CommonProperties.JSON_PROCESSING_FEATURE_DISABLE_SERVER</link>" >
@@ -605,6 +609,7 @@
605609
<!ENTITY jersey.server.ServerProperties.BV_SEND_ERROR_IN_RESPONSE "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#BV_SEND_ERROR_IN_RESPONSE'>ServerProperties.BV_SEND_ERROR_IN_RESPONSE</link>" >
606610
<!ENTITY jersey.server.ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#FEATURE_AUTO_DISCOVERY_DISABLE'>ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE</link>" >
607611
<!ENTITY jersey.server.ServerProperties.HTTP_METHOD_OVERRIDE "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#HTTP_METHOD_OVERRIDE'>ServerProperties.HTTP_METHOD_OVERRIDE</link>" >
612+
<!ENTITY jersey.server.ServerProperties.JSON_BINDING_FEATURE_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#JSON_BINDING_FEATURE_DISABLE'>ServerProperties.JSON_BINDING_FEATURE_DISABLE</link>" >
608613
<!ENTITY jersey.server.ServerProperties.JSON_PROCESSING_FEATURE_DISABLE "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#JSON_PROCESSING_FEATURE_DISABLE'>ServerProperties.JSON_PROCESSING_FEATURE_DISABLE</link>" >
609614
<!ENTITY jersey.server.ServerProperties.LANGUAGE_MAPPINGS "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#LANGUAGE_MAPPINGS'>ServerProperties.LANGUAGE_MAPPINGS</link>" >
610615
<!ENTITY jersey.server.ServerProperties.MEDIA_TYPE_MAPPINGS "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#MEDIA_TYPE_MAPPINGS'>ServerProperties.MEDIA_TYPE_MAPPINGS</link>" >

media/json-binding/src/main/java/org/glassfish/jersey/jsonb/JsonBindingFeature.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -56,6 +56,11 @@ public class JsonBindingFeature implements Feature {
5656
public boolean configure(final FeatureContext context) {
5757
final Configuration config = context.getConfiguration();
5858

59+
if (CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
60+
CommonProperties.JSON_BINDING_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) {
61+
return false;
62+
}
63+
5964
final String jsonFeature = CommonProperties.getValue(
6065
config.getProperties(),
6166
config.getRuntimeType(),

0 commit comments

Comments
 (0)