Skip to content

Commit

Permalink
Allow to disable JSON-B by a property
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Aug 16, 2024
1 parent 88ebd40 commit e254ae8
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,34 @@ public final class ClientProperties {
@PropertyAlias
public static final String OUTBOUND_CONTENT_LENGTH_BUFFER = CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER_CLIENT;

/**
* If {@code true} then disable configuration of Json Binding (JSR-367)
* feature on client.
* <p>
* By default, Json Binding on client is automatically enabled if global
* property
* {@value org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE}
* is not disabled. If set then the client property value overrides the
* global property value.
* <p>
* The default value is {@code false}.
* </p>
* <p>
* The name of the configuration property is <tt>{@value}</tt>.
* </p>
* <p>This constant is an alias for {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE_CLIENT}.</p>
*
* @see org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE
* @since 2.45
*/
@PropertyAlias
public static final String JSON_BINDING_FEATURE_DISABLE = CommonProperties.JSON_BINDING_FEATURE_DISABLE_CLIENT;

/**
* If {@code true} then disable configuration of Json Processing (JSR-353)
* feature on client.
* <p>
* By default Json Processing on client is automatically enabled if global
* By default, Json Processing on client is automatically enabled if global
* property
* {@value org.glassfish.jersey.CommonProperties#JSON_PROCESSING_FEATURE_DISABLE}
* is not disabled. If set then the client property value overrides the
Expand All @@ -265,7 +288,7 @@ public final class ClientProperties {
/**
* If {@code true} then disable META-INF/services lookup on client.
* <p>
* By default Jersey looks up SPI implementations described by {@code META-INF/services/*} files.
* By default, Jersey looks up SPI implementations described by {@code META-INF/services/*} files.
* Then you can register appropriate provider classes by {@link javax.ws.rs.core.Application}.
* </p>
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class CommonProperties {
/**
* If {@code true} then disable feature auto discovery globally on client/server.
* <p>
* By default auto discovery is automatically enabled. The value of this property may be overridden by the client/server
* By default, auto discovery is automatically enabled. The value of this property may be overridden by the client/server
* variant of this property.
* <p>
* The default value is {@code false}.
Expand All @@ -98,10 +98,42 @@ public final class CommonProperties {
*/
public static final String FEATURE_AUTO_DISCOVERY_DISABLE_SERVER = "jersey.config.server.disableAutoDiscovery";


/**
* If {@code true} then disable configuration of Json Binding (JSR-367) feature.
* <p>
* By default, Json Binding is automatically enabled. The value of this property may be overridden by the client/server
* variant of this property.
* <p>
* The default value is {@code false}.
* </p>
* <p>
* The name of the configuration property is <tt>{@value}</tt>.
* </p>
* @since 2.45
*/
public static final String JSON_BINDING_FEATURE_DISABLE = "jersey.config.disableJsonBinding";

/**
* Client-specific version of {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE}.
*
* If present, it overrides the generic one for the client environment.
* @since 2.45
*/
public static final String JSON_BINDING_FEATURE_DISABLE_CLIENT = "jersey.config.client.disableJsonBinding";

/**
* Server-specific version of {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE}.
*
* If present, it overrides the generic one for the server environment.
* @since 2.45
*/
public static final String JSON_BINDING_FEATURE_DISABLE_SERVER = "jersey.config.server.disableJsonBinding";

/**
* If {@code true} then disable configuration of Json Processing (JSR-353) feature.
* <p>
* By default Json Processing is automatically enabled. The value of this property may be overridden by the client/server
* By default, Json Processing is automatically enabled. The value of this property may be overridden by the client/server
* variant of this property.
* <p>
* The default value is {@code false}.
Expand Down Expand Up @@ -131,7 +163,7 @@ public final class CommonProperties {
/**
* If {@code true} then disable META-INF/services lookup globally on client/server.
* <p>
* By default Jersey looks up SPI implementations described by META-INF/services/* files.
* By default, Jersey looks up SPI implementations described by META-INF/services/* files.
* Then you can register appropriate provider classes by {@link javax.ws.rs.core.Application}.
* </p>
* <p>
Expand Down Expand Up @@ -164,7 +196,7 @@ public final class CommonProperties {
/**
* If {@code true} then disable configuration of MOXy Json feature.
* <p>
* By default MOXy Json is automatically enabled. The value of this property may be overridden by the client/server
* By default, MOXy Json is automatically enabled. The value of this property may be overridden by the client/server
* variant of this property.
* <p>
* The default value is {@code false}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -302,7 +302,7 @@ public final class ServerProperties {
/**
* If {@code true} then disable auto discovery on server.
*
* By default auto discovery is automatically enabled if global property
* By default, auto discovery is automatically enabled if global property
* {@value org.glassfish.jersey.CommonProperties#FEATURE_AUTO_DISCOVERY_DISABLE} is not disabled. If set then the server
* property value overrides the global property value.
* <p>
Expand Down Expand Up @@ -342,10 +342,29 @@ public final class ServerProperties {
@PropertyAlias
public static final String OUTBOUND_CONTENT_LENGTH_BUFFER = CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER_SERVER;

/**
* If {@code true} then disable configuration of Json Binding (JSR-367) feature on server.
*
* By default, Json Binding is automatically enabled if global property
* {@value org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE} is not disabled. If set then the server
* property value overrides the global property value.
* <p>
* The default value is {@code false}.
* </p>
* <p>
* The name of the configuration property is <tt>{@value}</tt>.
* </p>
* <p>This constant is an alias for {@link CommonProperties#JSON_BINDING_FEATURE_DISABLE_SERVER}</p>
*
* @see org.glassfish.jersey.CommonProperties#JSON_BINDING_FEATURE_DISABLE
*/
@PropertyAlias
public static final String JSON_BINDING_FEATURE_DISABLE = CommonProperties.JSON_BINDING_FEATURE_DISABLE_SERVER;

/**
* If {@code true} then disable configuration of Json Processing (JSR-353) feature on server.
*
* By default Json Processing is automatically enabled if global property
* By default, Json Processing is automatically enabled if global property
* {@value org.glassfish.jersey.CommonProperties#JSON_PROCESSING_FEATURE_DISABLE} is not disabled. If set then the server
* property value overrides the global property value.
* <p>
Expand All @@ -364,7 +383,7 @@ public final class ServerProperties {
/**
* If {@code true} then disable META-INF/services lookup on server.
*
* By default Jersey looks up SPI implementations described by META-INF/services/* files.
* By default, Jersey looks up SPI implementations described by META-INF/services/* files.
* Then you can register appropriate provider classes by {@link javax.ws.rs.core.Application}.
* <p>
* The default value is {@code false}.
Expand All @@ -383,7 +402,7 @@ public final class ServerProperties {
/**
* If {@code true} then disable configuration of MOXy Json feature on server.
*
* By default MOXy Json is automatically enabled if global property
* By default, MOXy Json is automatically enabled if global property
* {@value org.glassfish.jersey.CommonProperties#MOXY_JSON_FEATURE_DISABLE} is not disabled. If set then the server
* property value overrides the global property value.
* <p>
Expand Down
34 changes: 34 additions & 0 deletions docs/src/main/docbook/appendix-properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@
</para>
</entry>
</row>
<row>
<entry>&jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE; /
&jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE_CLIENT; /
&jersey.common.CommonProperties.JSON_BINDING_FEATURE_DISABLE_SERVER;</entry>
<entry><literal>jersey.config.disableJsonBinding</literal> /
<literal>jersey.config.client.disableJsonBinding</literal> /
<literal>jersey.config.server.disableJsonBinding</literal></entry>
<entry>
<para>
Disables configuration of Json Binding (JSR-367) feature. Default value is <literal>false</literal>.
</para>
<para>
Since 2.45.
</para>
</entry>
</row>
<row>
<entry>&jersey.common.CommonProperties.JSON_PROCESSING_FEATURE_DISABLE; /
&jersey.common.CommonProperties.JSON_PROCESSING_FEATURE_DISABLE_CLIENT; /
Expand Down Expand Up @@ -391,6 +407,15 @@
</para>
</entry>
</row>
<row>
<entry>&jersey.server.ServerProperties.JSON_BINDING_FEATURE_DISABLE;</entry>
<entry><literal>jersey.config.server.disableJsonBinding</literal></entry>
<entry>
<para>
Disables configuration of Json Processing (JSR-353) feature. Default value is <literal>false</literal>.
</para>
</entry>
</row>
<row>
<entry>&jersey.server.ServerProperties.JSON_PROCESSING_FEATURE_DISABLE;</entry>
<entry><literal>jersey.config.server.disableJsonProcessing</literal></entry>
Expand Down Expand Up @@ -998,6 +1023,15 @@
</para>
</entry>
</row>
<row>
<entry>&jersey.client.ClientProperties.JSON_BINDING_FEATURE_DISABLE;</entry>
<entry><literal>jersey.config.client.disableJsonBinding</literal></entry>
<entry>
<para>
Disables configuration of Json Binding (JSR-367) feature. Default value is <literal>false</literal>.
</para>
</entry>
</row>
<row>
<entry>&jersey.client.ClientProperties.JSON_PROCESSING_FEATURE_DISABLE;</entry>
<entry><literal>jersey.config.client.disableJsonProcessing</literal></entry>
Expand Down
5 changes: 5 additions & 0 deletions docs/src/main/docbook/jersey.ent
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
<!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>" >
<!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>" >
<!ENTITY jersey.client.ClientProperties.FOLLOW_REDIRECTS "<link xlink:href='&jersey.javadoc.uri.prefix;/client/ClientProperties.html#FOLLOW_REDIRECTS'>ClientProperties.FOLLOW_REDIRECTS</link>" >
<!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>" >
<!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>" >
<!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>" >
<!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>" >
Expand Down Expand Up @@ -388,6 +389,9 @@
<!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>" >
<!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>" >
<!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>" >
<!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>" >
<!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>" >
<!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>" >
<!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>" >
<!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>" >
<!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>" >
Expand Down Expand Up @@ -605,6 +609,7 @@
<!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>" >
<!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>" >
<!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>" >
<!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>" >
<!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>" >
<!ENTITY jersey.server.ServerProperties.LANGUAGE_MAPPINGS "<link xlink:href='&jersey.javadoc.uri.prefix;/server/ServerProperties.html#LANGUAGE_MAPPINGS'>ServerProperties.LANGUAGE_MAPPINGS</link>" >
<!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>" >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -56,6 +56,11 @@ public class JsonBindingFeature implements Feature {
public boolean configure(final FeatureContext context) {
final Configuration config = context.getConfiguration();

if (CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
CommonProperties.JSON_BINDING_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) {
return false;
}

final String jsonFeature = CommonProperties.getValue(
config.getProperties(),
config.getRuntimeType(),
Expand Down
Loading

0 comments on commit e254ae8

Please sign in to comment.