All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juneau.CoreObjectBuilder Maven / Gradle / Ivy

There is a newer version: 9.0.1
Show newest version
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
// * with the License.  You may obtain a copy of the License at                                                              *
// *                                                                                                                         *
// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
// *                                                                                                                         *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
// * specific language governing permissions and limitations under the License.                                              *
// ***************************************************************************************************************************
package org.apache.juneau;

import static org.apache.juneau.BeanContext.*;
import static org.apache.juneau.internal.ClassUtils.*;

import java.beans.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;

import org.apache.juneau.annotation.*;
import org.apache.juneau.http.*;
import org.apache.juneau.json.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.transform.*;

/**
 * Builder class for building instances of serializers and parsers.
 */
public abstract class CoreObjectBuilder {

	/** Contains all the modifiable settings for the implementation class. */
	protected final PropertyStore propertyStore;

	/**
	 * Constructor.
	 * Default settings.
	 */
	public CoreObjectBuilder() {
		this.propertyStore = PropertyStore.create();
	}

	/**
	 * Constructor.
	 *
	 * @param propertyStore The initial configuration settings for this builder.
	 */
	public CoreObjectBuilder(PropertyStore propertyStore) {
		this.propertyStore = propertyStore.copy();
	}

	/**
	 * Build the object.
	 *
	 * @return The built object.
	 * Subsequent calls to this method will create new instances.
	 */
	public abstract CoreObject build();

	/**
	 * Copies the settings from the specified property store into this builder.
	 *
	 * @param copyFrom The factory whose settings are being copied.
	 * @return This object (for method chaining).
	 */
	public CoreObjectBuilder apply(PropertyStore copyFrom) {
		this.propertyStore.copyFrom(propertyStore);
		return this;
	}

	/**
	 * Build a new instance of the specified object.
	 *
	 * @param c The subclass of {@link CoreObject} to instantiate.
	 * @return A new object using the settings defined in this builder.
	 */
	@SuppressWarnings("unchecked")
	public  T build(Class c) {
		return (T)newInstance(CoreObject.class, c, propertyStore);
	}

	//--------------------------------------------------------------------------------
	// Properties
	//--------------------------------------------------------------------------------

	/**
	 * Sets a configuration property on this object.
	 *
	 * @param name The property name.
	 * @param value The property value.
	 * @return This object (for method chaining).
	 * @see PropertyStore#setProperty(String, Object)
	 */
	public CoreObjectBuilder property(String name, Object value) {
		propertyStore.setProperty(name, value);
		return this;
	}

	/**
	 * Adds multiple configuration properties on this object.
	 *
	 * 
Notes:
*
    *
  • This is equivalent to calling {@link PropertyStore#addProperties(Map)}. *
  • Any previous properties are kept if they're not overwritten. *
* * @param properties The properties to set on this class. * @return This object (for method chaining). * @see PropertyStore#addProperties(java.util.Map) */ public CoreObjectBuilder properties(Map properties) { propertyStore.addProperties(properties); return this; } /** * Sets multiple configuration properties on this object. * *
Notes:
*
    *
  • This is equivalent to calling {@link PropertyStore#setProperties(Map)}. *
  • Any previous properties are discarded. *
* * @param properties The properties to set on this class. * @return This object (for method chaining). * @see PropertyStore#setProperties(java.util.Map) */ public CoreObjectBuilder setProperties(Map properties) { propertyStore.setProperties(properties); return this; } /** * Adds a value to a SET property. * *
Notes:
*
    *
  • This is equivalent to calling PropertyStore.addToProperty(name, value);. *
* * @param name The property name. * @param value The new value to add to the SET property. * @return This object (for method chaining). * @throws ConfigException If property is not a SET property. */ public CoreObjectBuilder addToProperty(String name, Object value) { propertyStore.addToProperty(name, value); return this; } /** * Adds or overwrites a value to a MAP property. * *
Notes:
*
    *
  • This is equivalent to calling PropertyStore.putToProperty(name, key, value);. *
* * @param name The property name. * @param key The property value map key. * @param value The property value map value. * @return This object (for method chaining). * @throws ConfigException If property is not a MAP property. */ public CoreObjectBuilder putToProperty(String name, Object key, Object value) { propertyStore.putToProperty(name, key, value); return this; } /** * Adds or overwrites a value to a MAP property. * *
Notes:
*
    *
  • This is equivalent to calling PropertyStore.putToProperty(name, value);. *
* * @param name The property value. * @param value The property value map value. * @return This object (for method chaining). * @throws ConfigException If property is not a MAP property. */ public CoreObjectBuilder putToProperty(String name, Object value) { propertyStore.putToProperty(name, value); return this; } /** * Removes a value from a SET property. * *
Notes:
*
    *
  • This is equivalent to calling PropertyStore.removeFromProperty(name, value);. *
* * @param name The property name. * @param value The property value in the SET property. * @return This object (for method chaining). * @throws ConfigException If property is not a SET property. */ public CoreObjectBuilder removeFromProperty(String name, Object value) { propertyStore.removeFromProperty(name, value); return this; } /** * Configuration property: Beans require no-arg constructors. * *
    *
  • Name: "BeanContext.beansRequireDefaultConstructor" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* If true, a Java class must implement a default no-arg constructor to be considered a bean. * Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. * *

* The {@link Bean @Bean} annotation can be used on a class to override this setting when true. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beansRequireDefaultConstructor, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beansRequireDefaultConstructor */ public CoreObjectBuilder beansRequireDefaultConstructor(boolean value) { return property(BEAN_beansRequireDefaultConstructor, value); } /** * Configuration property: Beans require {@link Serializable} interface. * *
    *
  • Name: "BeanContext.beansRequireSerializable" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* If true, a Java class must implement the {@link Serializable} interface to be considered a bean. * Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. * *

* The {@link Bean @Bean} annotation can be used on a class to override this setting when true. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beansRequireSerializable, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beansRequireSerializable */ public CoreObjectBuilder beansRequireSerializable(boolean value) { return property(BEAN_beansRequireSerializable, value); } /** * Configuration property: Beans require setters for getters. * *
    *
  • Name: "BeanContext.beansRequireSettersForGetters" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* If true, only getters that have equivalent setters will be considered as properties on a bean. * Otherwise, they will be ignored. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beansRequireSettersForGetters, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beansRequireSettersForGetters */ public CoreObjectBuilder beansRequireSettersForGetters(boolean value) { return property(BEAN_beansRequireSettersForGetters, value); } /** * Configuration property: Beans require at least one property. * *
    *
  • Name: "BeanContext.beansRequireSomeProperties" *
  • Data type: Boolean *
  • Default: true *
  • Session-overridable: false *
* *

* If true, then a Java class must contain at least 1 property to be considered a bean. * Otherwise, the bean will be serialized as a string using the {@link Object#toString()} method. * *

* The {@link Bean @Bean} annotation can be used on a class to override this setting when true. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beansRequireSomeProperties, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beansRequireSomeProperties */ public CoreObjectBuilder beansRequireSomeProperties(boolean value) { return property(BEAN_beansRequireSomeProperties, value); } /** * Configuration property: {@link BeanMap#put(String,Object) BeanMap.put()} method will return old property * value. * *
    *
  • Name: "BeanContext.beanMapPutReturnsOldValue" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* If true, then the {@link BeanMap#put(String,Object) BeanMap.put()} method will return old property * values. * Otherwise, it returns null. * *

* Disabled by default because it introduces a slight performance penalty. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beanMapPutReturnsOldValue, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanMapPutReturnsOldValue */ public CoreObjectBuilder beanMapPutReturnsOldValue(boolean value) { return property(BEAN_beanMapPutReturnsOldValue, value); } /** * Configuration property: Look for bean constructors with the specified minimum visibility. * *
    *
  • Name: "BeanContext.beanConstructorVisibility" *
  • Data type: {@link Visibility} *
  • Default: {@link Visibility#PUBLIC} *
  • Session-overridable: false *
* *

* Constructors not meeting this minimum visibility will be ignored. * For example, if the visibility is PUBLIC and the constructor is protected, then the * constructor will be ignored. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beanConstructorVisibility, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanConstructorVisibility */ public CoreObjectBuilder beanConstructorVisibility(Visibility value) { return property(BEAN_beanConstructorVisibility, value); } /** * Configuration property: Look for bean classes with the specified minimum visibility. * *
    *
  • Name: "BeanContext.beanClassVisibility" *
  • Data type: {@link Visibility} *
  • Default: {@link Visibility#PUBLIC} *
  • Session-overridable: false *
* *

* Classes are not considered beans unless they meet the minimum visibility requirements. * For example, if the visibility is PUBLIC and the bean class is protected, then the class * will not be interpreted as a bean class. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beanClassVisibility, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanClassVisibility */ public CoreObjectBuilder beanClassVisibility(Visibility value) { return property(BEAN_beanClassVisibility, value); } /** * Configuration property: Look for bean fields with the specified minimum visibility. * *
    *
  • Name: "BeanContext.beanFieldVisibility" *
  • Data type: {@link Visibility} *
  • Default: {@link Visibility#PUBLIC} *
  • Session-overridable: false *
* *

* Fields are not considered bean properties unless they meet the minimum visibility requirements. * For example, if the visibility is PUBLIC and the bean field is protected, then the field * will not be interpreted as a bean property. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_beanFieldVisibility, value). *
  • Use {@link Visibility#NONE} to prevent bean fields from being interpreted as bean properties altogether. *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanFieldVisibility */ public CoreObjectBuilder beanFieldVisibility(Visibility value) { return property(BEAN_beanFieldVisibility, value); } /** * Configuration property: Look for bean methods with the specified minimum visibility. * *
    *
  • Name: "BeanContext.methodVisibility" *
  • Data type: {@link Visibility} *
  • Default: {@link Visibility#PUBLIC} *
  • Session-overridable: false *
* *

* Methods are not considered bean getters/setters unless they meet the minimum visibility requirements. * For example, if the visibility is PUBLIC and the bean method is protected, then the method * will not be interpreted as a bean getter or setter. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_methodVisibility, value). *
  • Use {@link Visibility#NONE} to prevent bean methods from being interpreted as bean properties altogether. *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_methodVisibility */ public CoreObjectBuilder methodVisibility(Visibility value) { return property(BEAN_methodVisibility, value); } /** * Configuration property: Use Java {@link Introspector} for determining bean properties. * *
    *
  • Name: "BeanContext.useJavaBeanIntrospector" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_useJavaBeanIntrospector, value). *
  • Most {@link Bean @Bean} annotations will be ignored if you enable this setting. *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_useJavaBeanIntrospector */ public CoreObjectBuilder useJavaBeanIntrospector(boolean value) { return property(BEAN_useJavaBeanIntrospector, value); } /** * Configuration property: Use interface proxies. * *
    *
  • Name: "BeanContext.useInterfaceProxies" *
  • Data type: Boolean *
  • Default: true *
  • Session-overridable: false *
* *

* If true, then interfaces will be instantiated as proxy classes through the use of an * {@link InvocationHandler} if there is no other way of instantiating them. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_useInterfaceProxies, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_useInterfaceProxies */ public CoreObjectBuilder useInterfaceProxies(boolean value) { return property(BEAN_useInterfaceProxies, value); } /** * Configuration property: Ignore unknown properties. * *
    *
  • Name: "BeanContext.ignoreUnknownBeanProperties" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* If true, trying to set a value on a non-existent bean property will silently be ignored. * Otherwise, a {@code BeanRuntimeException} is thrown. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_ignoreUnknownBeanProperties, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_ignoreUnknownBeanProperties */ public CoreObjectBuilder ignoreUnknownBeanProperties(boolean value) { return property(BEAN_ignoreUnknownBeanProperties, value); } /** * Configuration property: Ignore unknown properties with null values. * *
    *
  • Name: "BeanContext.ignoreUnknownNullBeanProperties" *
  • Data type: Boolean *
  • Default: true *
  • Session-overridable: false *
* *

* If true, trying to set a null value on a non-existent bean property will silently be ignored. * Otherwise, a {@code BeanRuntimeException} is thrown. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_ignoreUnknownNullBeanProperties, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_ignoreUnknownNullBeanProperties */ public CoreObjectBuilder ignoreUnknownNullBeanProperties(boolean value) { return property(BEAN_ignoreUnknownNullBeanProperties, value); } /** * Configuration property: Ignore properties without setters. * *
    *
  • Name: "BeanContext.ignorePropertiesWithoutSetters" *
  • Data type: Boolean *
  • Default: true *
  • Session-overridable: false *
* *

* If true, trying to set a value on a bean property without a setter will silently be ignored. * Otherwise, a {@code BeanRuntimeException} is thrown. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_ignorePropertiesWithoutSetters, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_ignorePropertiesWithoutSetters */ public CoreObjectBuilder ignorePropertiesWithoutSetters(boolean value) { return property(BEAN_ignorePropertiesWithoutSetters, value); } /** * Configuration property: Ignore invocation errors on getters. * *
    *
  • Name: "BeanContext.ignoreInvocationExceptionsOnGetters" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* If true, errors thrown when calling bean getter methods will silently be ignored. * Otherwise, a {@code BeanRuntimeException} is thrown. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_ignoreInvocationExceptionsOnGetters, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_ignoreInvocationExceptionsOnGetters */ public CoreObjectBuilder ignoreInvocationExceptionsOnGetters(boolean value) { return property(BEAN_ignoreInvocationExceptionsOnGetters, value); } /** * Configuration property: Ignore invocation errors on setters. * *
    *
  • Name: "BeanContext.ignoreInvocationExceptionsOnSetters" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* If true, errors thrown when calling bean setter methods will silently be ignored. * Otherwise, a {@code BeanRuntimeException} is thrown. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_ignoreInvocationExceptionsOnSetters, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_ignoreInvocationExceptionsOnSetters */ public CoreObjectBuilder ignoreInvocationExceptionsOnSetters(boolean value) { return property(BEAN_ignoreInvocationExceptionsOnSetters, value); } /** * Configuration property: Sort bean properties in alphabetical order. * *
    *
  • Name: "BeanContext.sortProperties" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: false *
* *

* When true, all bean properties will be serialized and access in alphabetical order. * Otherwise, the natural order of the bean properties is used which is dependent on the JVM vendor. * On IBM JVMs, the bean properties are ordered based on their ordering in the Java file. * On Oracle JVMs, the bean properties are not ordered (which follows the official JVM specs). * *

Notes:
*
    *
  • * This is equivalent to calling property(BEAN_sortProperties, value). *
  • * This property is disabled by default so that IBM JVM users don't have to use {@link Bean @Bean} annotations * to force bean properties to be in a particular order and can just alter the order of the fields/methods * in the Java file. *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_sortProperties */ public CoreObjectBuilder sortProperties(boolean value) { return property(BEAN_sortProperties, value); } /** * Configuration property: Packages whose classes should not be considered beans. * *
    *
  • Name: "BeanContext.notBeanPackages.set" *
  • Data type: Set<String> *
  • Default: *
      *
    • java.lang *
    • java.lang.annotation *
    • java.lang.ref *
    • java.lang.reflect *
    • java.io *
    • java.net *
    • java.nio.* *
    • java.util.* *
    *
  • Session-overridable: false *
* *

* When specified, the current list of ignore packages are appended to. * *

* Any classes within these packages will be serialized to strings using {@link Object#toString()}. * *

* Note that you can specify prefix patterns to include all subpackages. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_notBeanPackages, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanPackages */ public CoreObjectBuilder setNotBeanPackages(String...values) { return property(BEAN_notBeanPackages, values); } /** * Configuration property: Packages whose classes should not be considered beans. * * Same as {@link #setNotBeanPackages(String...)} but using a Collection. * * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanPackages */ public CoreObjectBuilder setNotBeanPackages(Collection values) { return property(BEAN_notBeanPackages, values); } /** * Configuration property: Add to packages whose classes should not be considered beans. * *
Notes:
*
    *
  • This is equivalent to calling addToProperty(BEAN_notBeanPackages, values) * or property(BEAN_notBeanPackages_add, s). *
* * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanPackages_add */ public CoreObjectBuilder notBeanPackages(String...values) { return addToProperty(BEAN_notBeanPackages, values); } /** * Configuration property: Add to packages whose classes should not be considered beans. * *

* Same as {@link #notBeanPackages(String...)} but using a Collection. * * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanPackages */ public CoreObjectBuilder notBeanPackages(Collection values) { return addToProperty(BEAN_notBeanPackages, values); } /** * Configuration property: Remove from packages whose classes should not be considered beans. * *

Notes:
*
    *
  • This is equivalent to calling removeFromProperty(BEAN_notBeanPackages, values) * or property(BEAN_notBeanPackages_remove, s). *
* * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanPackages * @see BeanContext#BEAN_notBeanPackages_remove */ public CoreObjectBuilder removeNotBeanPackages(String...values) { return removeFromProperty(BEAN_notBeanPackages, values); } /** * Configuration property: Remove from packages whose classes should not be considered beans. * *

* Same as {@link #removeNotBeanPackages(String...)} but using a Collection. * * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanPackages * @see BeanContext#BEAN_notBeanPackages_remove */ public CoreObjectBuilder removeNotBeanPackages(Collection values) { return removeFromProperty(BEAN_notBeanPackages, values); } /** * Configuration property: Classes to be excluded from consideration as being beans. * *

    *
  • Name: "BeanContext.notBeanClasses.set" *
  • Data type: Set<Class> *
  • Default: empty set *
  • Session-overridable: false *
* *

* Not-bean classes are typically converted to Strings during serialization even if they appear to be * bean-like. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_notBeanClasses, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanClasses */ public CoreObjectBuilder setNotBeanClasses(Class...values) { return property(BEAN_notBeanClasses, values); } /** * Configuration property: Classes to be excluded from consideration as being beans. * *

* Same as {@link #setNotBeanClasses(Class...)} but using a Collection. * * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanPackages */ public CoreObjectBuilder setNotBeanClasses(Collection> values) { return property(BEAN_notBeanClasses, values); } /** * Configuration property: Add to classes that should not be considered beans. * *

Notes:
*
    *
  • This is equivalent to calling addToProperty(BEAN_notBeanClasses, values) * or property(BEAN_notBeanClasses_add, values). *
* * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanClasses * @see BeanContext#BEAN_notBeanClasses_add */ public CoreObjectBuilder notBeanClasses(Class...values) { return addToProperty(BEAN_notBeanClasses, values); } /** * Configuration property: Add to classes that should not be considered beans. * *

* Same as {@link #notBeanClasses(Class...)} but using a Collection. * * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanClasses * @see BeanContext#BEAN_notBeanClasses_add */ public CoreObjectBuilder notBeanClasses(Collection> values) { return addToProperty(BEAN_notBeanClasses, values); } /** * Configuration property: Remove from classes that should not be considered beans. * *

Notes:
*
    *
  • This is equivalent to calling removeFromProperty(BEAN_notBeanClasses, values) * or property(BEAN_notBeanClasses_remove, values). *
* * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanClasses * @see BeanContext#BEAN_notBeanClasses_remove */ public CoreObjectBuilder removeNotBeanClasses(Class...values) { return removeFromProperty(BEAN_notBeanClasses, values); } /** * Configuration property: Remove from classes that should not be considered beans. * *

* Same as {@link #removeNotBeanClasses(Class...)} but using a Collection. * * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_notBeanClasses * @see BeanContext#BEAN_notBeanClasses_remove */ public CoreObjectBuilder removeNotBeanClasses(Collection> values) { return removeFromProperty(BEAN_notBeanClasses, values); } /** * Configuration property: Bean filters to apply to beans. * *

    *
  • Name: "BeanContext.beanFilters.list" *
  • Data type: List<Class> *
  • Default: empty list *
  • Session-overridable: false *
* *

* This is a programmatic equivalent to the {@link Bean @Bean} annotation. * It's useful when you want to use the Bean annotation functionality, but you don't have the ability to alter the * bean classes. * *

* There are two category of classes that can be passed in through this method: *

    *
  • * Subclasses of {@link BeanFilterBuilder}. * These must have a public no-arg constructor. *
  • * Bean interface classes. * A shortcut for defining a {@link InterfaceBeanFilterBuilder}. * Any subclasses of an interface class will only have properties defined on the interface. * All other bean properties will be ignored. *
* *
Notes:
*
    *
  • This is equivalent to calling property(BEAN_beanFilters, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanFilters */ public CoreObjectBuilder setBeanFilters(Class...values) { return property(BEAN_beanFilters, values); } /** * Configuration property: Bean filters to apply to beans. * *

* Same as {@link #setBeanFilters(Class...)} but using a Collection. * * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanFilters */ public CoreObjectBuilder setBeanFilters(Collection> values) { return property(BEAN_beanFilters, values); } /** * Configuration property: Add to bean filters. * *

Notes:
*
    *
  • This is equivalent to calling addToProperty(BEAN_beanFilters, values) * or property(BEAN_beanFilters_add, values). *
* * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanFilters * @see BeanContext#BEAN_beanFilters_add */ public CoreObjectBuilder beanFilters(Class...values) { return addToProperty(BEAN_beanFilters, values); } /** * Configuration property: Add to bean filters. * *

* Same as {@link #beanFilters(Class...)} but using a Collection. * * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanFilters * @see BeanContext#BEAN_beanFilters_add */ public CoreObjectBuilder beanFilters(Collection> values) { return addToProperty(BEAN_beanFilters, values); } /** * Configuration property: Remove from bean filters. * *

Notes:
*
    *
  • This is equivalent to calling removeFromProperty(BEAN_beanFilters, values) * or property(BEAN_beanFilters_remove, values). *
* * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanFilters * @see BeanContext#BEAN_beanFilters_remove */ public CoreObjectBuilder removeBeanFilters(Class...values) { return removeFromProperty(BEAN_beanFilters, values); } /** * Configuration property: Remove from bean filters. * *

* Same as {@link #removeBeanFilters(Class...)} but using a Collection. * * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanFilters * @see BeanContext#BEAN_beanFilters_remove */ public CoreObjectBuilder removeBeanFilters(Collection> values) { return removeFromProperty(BEAN_beanFilters, values); } /** * Configuration property: POJO swaps to apply to Java objects. * *

    *
  • Name: "BeanContext.pojoSwaps.list" *
  • Data type: List<Class> *
  • Default: empty list *
  • Session-overridable: false *
* *

* There are two category of classes that can be passed in through this method: *

    *
  • Subclasses of {@link PojoSwap}. *
  • Implementations of {@link Surrogate}. *
* *
Notes:
*
    *
  • This is equivalent to calling property(BEAN_pojoSwaps, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_pojoSwaps */ public CoreObjectBuilder setPojoSwaps(Class...values) { return property(BEAN_pojoSwaps, values); } /** * Configuration property: POJO swaps to apply to Java objects. * *

* Same as {@link #setPojoSwaps(Class...)} but using a Collection. * * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_pojoSwaps */ public CoreObjectBuilder setPojoSwaps(Collection> values) { return property(BEAN_pojoSwaps, values); } /** * Configuration property: Add to POJO swaps. * *

Notes:
*
    *
  • This is equivalent to calling addToProperty(BEAN_pojoSwaps, values) * or property(BEAN_pojoSwaps_add, values). *
* * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_pojoSwaps * @see BeanContext#BEAN_pojoSwaps_add */ public CoreObjectBuilder pojoSwaps(Class...values) { return addToProperty(BEAN_pojoSwaps, values); } /** * Configuration property: Add to POJO swaps. * *

* Same as {@link #pojoSwaps(Class...)} but using a Collection. * * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_pojoSwaps * @see BeanContext#BEAN_pojoSwaps_add */ public CoreObjectBuilder pojoSwaps(Collection> values) { return addToProperty(BEAN_pojoSwaps, values); } /** * Configuration property: Remove from POJO swaps. * *

Notes:
*
    *
  • This is equivalent to calling removeFromProperty(BEAN_pojoSwaps, values) * or property(BEAN_pojoSwaps_remove, values). *
* * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_pojoSwaps * @see BeanContext#BEAN_pojoSwaps_remove */ public CoreObjectBuilder removePojoSwaps(Class...values) { return removeFromProperty(BEAN_pojoSwaps, values); } /** * Configuration property: Remove from POJO swaps. * *

* Same as {@link #removePojoSwaps(Class...)} but using a Collection. * * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_pojoSwaps * @see BeanContext#BEAN_pojoSwaps_remove */ public CoreObjectBuilder removePojoSwaps(Collection> values) { return removeFromProperty(BEAN_pojoSwaps, values); } /** * Configuration property: Implementation classes for interfaces and abstract classes. * *

    *
  • Name: "BeanContext.implClasses.map" *
  • Data type: Map<Class,Class> *
  • Default: empty map *
  • Session-overridable: false *
* *

* For interfaces and abstract classes this method can be used to specify an implementation class for the * interface/abstract class so that instances of the implementation class are used when instantiated (e.g. during a * parse). * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_implClasses, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_implClasses */ public CoreObjectBuilder implClasses(Map,Class> values) { return property(BEAN_implClasses, values); } /** * Configuration property: Implementation classes for interfaces and abstract classes. * *
Notes:
*
    *
  • This is equivalent to calling putToProperty(BEAN_implClasses, interfaceClass, implClass) * or property(BEAN_implClasses_put, interfaceClass, implClass). *
* * @param interfaceClass The interface class. * @param implClass The implementation class. * @param The class type of the interface. * @return This object (for method chaining). * @see BeanContext#BEAN_implClasses * @see BeanContext#BEAN_implClasses_put */ public CoreObjectBuilder implClass(Class interfaceClass, Class implClass) { return putToProperty(BEAN_implClasses, interfaceClass, implClass); } /** * Configuration property: Explicitly specify visible bean properties. * *
    *
  • Name: "BeanContext.includeProperties" *
  • Data type: Map<String,String> *
  • Default: {} *
  • Session-overridable: false *
* *

* Specifies to only include the specified list of properties for the specified bean classes. * *

* The keys are either fully-qualified or simple class names, and the values are comma-delimited lists of property * names. * The key "*" means all bean classes. * *

* For example, {Bean1:"foo,bar"} means only serialize the foo and bar * properties on the specified bean. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_includeProperties, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_includeProperties */ public CoreObjectBuilder includeProperties(Map values) { return property(BEAN_includeProperties, values); } /** * Configuration property: Explicitly specify visible bean properties. * *
Notes:
*
    *
  • This is equivalent to calling putToProperty(BEAN_includeProperties, beanClassName, properties) * or property(BEAN_includeProperties_put, beanClassName, properties). *
* * @param beanClassName The bean class name. Can be a simple name, fully-qualified name, or "*". * @param properties Comma-delimited list of property names. * @return This object (for method chaining). * @see BeanContext#BEAN_includeProperties * @see BeanContext#BEAN_includeProperties_put */ public CoreObjectBuilder includeProperties(String beanClassName, String properties) { return putToProperty(BEAN_includeProperties, beanClassName, properties); } /** * Configuration property: Explicitly specify visible bean properties. * *
Notes:
*
    *
  • This is equivalent to calling putToProperty(BEAN_includeProperties, beanClass.getName(), properties) * or property(BEAN_includeProperties_put, beanClass.getName(), properties). *
* * @param beanClass The bean class. * @param properties Comma-delimited list of property names. * @return This object (for method chaining). * @see BeanContext#BEAN_includeProperties * @see BeanContext#BEAN_includeProperties_put */ public CoreObjectBuilder includeProperties(Class beanClass, String properties) { return putToProperty(BEAN_includeProperties, beanClass.getName(), properties); } /** * Configuration property: Exclude specified properties from beans. * *
    *
  • Name: "BeanContext.excludeProperties" *
  • Data type: Map<String,String> *
  • Default: {} *
  • Session-overridable: false *
* *

* Specifies to exclude the specified list of properties for the specified bean classes. * *

* The keys are either fully-qualified or simple class names, and the values are comma-delimited lists of property * names. * The key "*" means all bean classes. * *

* For example, {Bean1:"foo,bar"} means don't serialize the foo and bar * properties on the specified bean. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_excludeProperties, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_excludeProperties */ public CoreObjectBuilder excludeProperties(Map values) { return property(BEAN_excludeProperties, values); } /** * Configuration property: Exclude specified properties from beans. * *
Notes:
*
    *
  • This is equivalent to calling putToProperty(BEAN_excludeProperties, beanClassName, properties) * or property(BEAN_excludeProperties_put, beanClassName, properties). *
* * @param beanClassName The bean class name. Can be a simple name, fully-qualified name, or "*". * @param properties Comma-delimited list of property names. * @return This object (for method chaining). * @see BeanContext#BEAN_excludeProperties * @see BeanContext#BEAN_excludeProperties_put */ public CoreObjectBuilder excludeProperties(String beanClassName, String properties) { return putToProperty(BEAN_excludeProperties, beanClassName, properties); } /** * Configuration property: Exclude specified properties from beans. * *
Notes:
*
    *
  • This is equivalent to calling putToProperty(BEAN_excludeProperties, beanClass.getName(), properties) * or property(BEAN_excludeProperties_put, beanClass.getName(), properties). *
* * @param beanClass The bean class. * @param properties Comma-delimited list of property names. * @return This object (for method chaining). * @see BeanContext#BEAN_excludeProperties * @see BeanContext#BEAN_excludeProperties_put */ public CoreObjectBuilder excludeProperties(Class beanClass, String properties) { return putToProperty(BEAN_excludeProperties, beanClass.getName(), properties); } /** * Configuration property: Bean lookup dictionary. * *
    *
  • Name: "BeanContext.beanDictionary.list" *
  • Data type: List<Class> *
  • Default: empty list *
  • Session-overridable: false *
* *

* This list can consist of the following class types: *

    *
  • Any bean class that specifies a value for {@link Bean#typeName() @Bean.typeName()}. *
  • Any subclass of {@link BeanDictionaryList} containing a collection of bean classes with type name * annotations. *
  • Any subclass of {@link BeanDictionaryMap} containing a mapping of type names to classes without type name * annotations. *
* *
Notes:
*
    *
  • This is equivalent to calling property(BEAN_beanDictionary, values). *
* * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanDictionary */ public CoreObjectBuilder setBeanDictionary(Class...values) { return property(BEAN_beanDictionary, values); } /** * Configuration property: Bean lookup dictionary. * *

* Same as {@link #setBeanDictionary(Class...)} but using a Collection. * * @param values The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanDictionary */ public CoreObjectBuilder setBeanDictionary(Collection> values) { return property(BEAN_beanDictionary, values); } /** * Configuration property: Add to bean dictionary. * *

Notes:
*
    *
  • This is equivalent to calling addToProperty(BEAN_beanDictionary, values) * or property(BEAN_beanDictionary_add, values). *
* * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanDictionary * @see BeanContext#BEAN_beanDictionary_add */ public CoreObjectBuilder beanDictionary(Class...values) { return addToProperty(BEAN_beanDictionary, values); } /** * Configuration property: Add to bean dictionary. * *

* Same as {@link #beanDictionary(Class...)} but using a Collection. * * @param values The values to add to this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanDictionary * @see BeanContext#BEAN_beanDictionary_add */ public CoreObjectBuilder beanDictionary(Collection> values) { return addToProperty(BEAN_beanDictionary, values); } /** * Configuration property: Remove from bean dictionary. * *

Notes:
*
    *
  • This is equivalent to calling removeFromProperty(BEAN_beanDictionary, values) * or property(BEAN_beanDictionary_remove, values). *
* * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanDictionary * @see BeanContext#BEAN_beanDictionary_remove */ public CoreObjectBuilder removeFromBeanDictionary(Class...values) { return removeFromProperty(BEAN_beanDictionary, values); } /** * Configuration property: Remove from bean dictionary. * *

* Same as {@link #removeFromBeanDictionary(Class...)} but using a Collection. * * @param values The values to remove from this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanDictionary * @see BeanContext#BEAN_beanDictionary_remove */ public CoreObjectBuilder removeFromBeanDictionary(Collection> values) { return removeFromProperty(BEAN_beanDictionary, values); } /** * Configuration property: Name to use for the bean type properties used to represent a bean type. * *

    *
  • Name: "BeanContext.beanTypePropertyName" *
  • Data type: String *
  • Default: "_type" *
  • Session-overridable: false *
* *
Notes:
*
    *
  • This is equivalent to calling property(BEAN_beanTypePropertyName, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_beanTypePropertyName */ public CoreObjectBuilder beanTypePropertyName(String value) { return property(BEAN_beanTypePropertyName, value); } /** * Configuration property: Default parser to use when converting Strings to POJOs. * *
    *
  • Name: "BeanContext.defaultParser" *
  • Data type: Class *
  • Default: {@link JsonSerializer} *
  • Session-overridable: false *
* *

* Used in the in the {@link BeanSession#convertToType(Object, Class)} method. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_defaultParser, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_defaultParser */ public CoreObjectBuilder defaultParser(Class value) { return property(BEAN_defaultParser, value); } /** * Configuration property: Locale. * *
    *
  • Name: "BeanContext.locale" *
  • Data type: Locale *
  • Default: Locale.getDefault() *
  • Session-overridable: true *
* *
Notes:
*
    *
  • This is equivalent to calling property(BEAN_locale, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_locale */ public CoreObjectBuilder locale(Locale value) { return property(BEAN_locale, value); } /** * Configuration property: TimeZone. * *
    *
  • Name: "BeanContext.timeZone" *
  • Data type: TimeZone *
  • Default: null *
  • Session-overridable: true *
* *
Notes:
*
    *
  • This is equivalent to calling property(BEAN_timeZone, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_timeZone */ public CoreObjectBuilder timeZone(TimeZone value) { return property(BEAN_timeZone, value); } /** * Configuration property: Media type. * *
    *
  • Name: "BeanContext.mediaType" *
  • Data type: MediaType *
  • Default: null *
  • Session-overridable: true *
* *

* Specifies a default media type value for serializer and parser sessions. * *

Notes:
*
    *
  • This is equivalent to calling property(BEAN_mediaType, value). *
* * @param value The new value for this property. * @return This object (for method chaining). * @see BeanContext#BEAN_mediaType */ public CoreObjectBuilder mediaType(MediaType value) { return property(BEAN_mediaType, value); } /** * Configuration property: Debug mode. * *
    *
  • Name: "BeanContext.debug" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: true *
* *

* Enables the following additional information during serialization: *

    *
  • * When bean getters throws exceptions, the exception includes the object stack information * in order to determine how that method was invoked. *
  • * Enables {@link Serializer#SERIALIZER_detectRecursions}. *
* *

* Enables the following additional information during parsing: *

    *
  • * When bean setters throws exceptions, the exception includes the object stack information * in order to determine how that method was invoked. *
* *
Notes:
*
    *
  • This is equivalent to calling property(BEAN_debug, value). *
* * @return This object (for method chaining). * @see BeanContext#BEAN_debug */ public CoreObjectBuilder debug() { return property(BEAN_debug, true); } /** * Sets the classloader used for created classes from class strings. * * @param classLoader The new classloader. * @return This object (for method chaining). * @see PropertyStore#setClassLoader(ClassLoader) */ public CoreObjectBuilder classLoader(ClassLoader classLoader) { propertyStore.setClassLoader(classLoader); return this; } }