javax.json.bind.JsonbConfig Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package javax.json.bind;
import javax.json.bind.adapter.JsonbAdapter;
import javax.json.bind.config.PropertyNamingStrategy;
import javax.json.bind.config.PropertyVisibilityStrategy;
import javax.json.bind.serializer.JsonbDeserializer;
import javax.json.bind.serializer.JsonbSerializer;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
/**
*
*
* All JSON Binding providers are required to support the following set of properties.
* Some providers may support additional properties.
*
* - jsonb.to.json.formatted - java.lang.Boolean
*
- Controls whether or not the {@link javax.json.bind.Jsonb Jsonb} {@code toJson()}
* methods will format the resulting JSON data with line breaks and indentation. A
* true value for this property indicates human readable indented
* data, while a false value indicates unformatted data.
* Default value is false (unformatted) if this property is not specified.
*
*
* - jsonb.to.json.encoding - java.lang.String
*
- The {@link javax.json.bind.Jsonb Jsonb} serialization {@code toJson()} methods
* will default to this property for encoding of output JSON data. Default
* value is 'UTF-8' if this property is not specified.
*
*
* - jsonb.from.json.encoding - java.lang.String
*
- The {@link javax.json.bind.Jsonb Jsonb} deserialization {@code fromJson()}
* methods will default to this property encoding of input JSON data if the
* encoding cannot be detected.
*
*
*
* This object is not thread safe. Implementations are expected to make a defensive copy
* of the object before applying the configuration.
*
* @since JSON Binding 1.0
*/
public class JsonbConfig {
private final Map configuration = new HashMap<>();
/**
* Property used to specify whether or not the serialized
* JSON data is formatted with line feeds and indentation.
*/
public static final String FORMATTING = "jsonb.formatting";
/**
* The Jsonb serialization {@code toJson()} methods will default to this property
* for encoding of output JSON data. Default value is 'UTF-8'.
*
* The Jsonb deserialization {@code fromJson()} methods will default to this
* property encoding of input JSON data if the encoding cannot be detected
* automatically.
*/
public static final String ENCODING = "jsonb.encoding";
/**
* Property used to specify custom naming strategy.
*/
public static final String PROPERTY_NAMING_STRATEGY = "jsonb.property-naming-strategy";
/**
* Property used to specify custom order strategy.
*/
public static final String PROPERTY_ORDER_STRATEGY = "jsonb.property-order-strategy";
/**
* Property used to specify null values serialization behavior.
*/
public static final String NULL_VALUES = "jsonb.null-values";
/**
* Property used to specify strict I-JSON serialization compliance.
*/
public static final String STRICT_IJSON = "jsonb.strict-ijson";
/**
* Property used to specify custom visibility strategy.
*/
public static final String PROPERTY_VISIBILITY_STRATEGY = "jsonb.property-visibility-strategy";
/**
* Property used to specify custom mapping adapters for generic types.
*/
public static final String ADAPTERS = "jsonb.adapters";
/**
* Property used to specify custom serializers.
*/
public static final String SERIALIZERS = "jsonb.serializers";
/**
* Property used to specify custom deserializers.
*/
public static final String DESERIALIZERS = "jsonb.derializers";
/**
* Property used to specify custom binary data strategy.
*/
public static final String BINARY_DATA_STRATEGY = "jsonb.binary-data-strategy";
/**
* Property used to specify custom date format globally.
*/
public static final String DATE_FORMAT = "jsonb.date-format";
/**
* Property used to specify locale globally.
*/
public static final String LOCALE = "jsonb.locale";
/**
* Set the particular configuration property to a new value. The method can
* only be used to set one of the standard JSON Binding properties defined in
* this class or a provider specific property. Attempting to set an undefined
* property will result in a JsonbException being thrown.
* See Supported Properties.
*
* @param name
* The name of the property to be set. This value can either
* be specified using one of the constant fields or a user supplied
* string.
* @param value
* The value of the property to be set
*
* @return This JsonbConfig instance.
*
* @throws NullPointerException if the name parameter is null.
*/
public final JsonbConfig setProperty(final String name, final Object value) {
configuration.put(name, value);
return this;
}
/**
* Return value of particular configuration property. The method can
* only be used to retrieve one of the standard JSON Binding properties defined
* in this class or a provider specific property. Attempting to get an undefined
* property will result in an empty Optional value.
* See Supported Properties.
*
* @param name
* The name of the property to retrieve
*
* @return The value of the requested property
*
* @throws NullPointerException if the name parameter is null.
*/
public final Optional