org.apache.juneau.BeanContext Maven / Gradle / Ivy
// ***************************************************************************************************************************
// * 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.Visibility.*;
import static org.apache.juneau.internal.ClassUtils.*;
import static org.apache.juneau.internal.CollectionUtils.*;
import static org.apache.juneau.internal.StringUtils.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.http.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.transform.*;
/**
* Core class of the Juneau architecture.
*
*
* This class servers multiple purposes:
*
* -
* Provides the ability to wrap beans inside {@link Map} interfaces.
*
-
* Serves as a repository for metadata on POJOs, such as associated {@link BeanFilter BeanFilters},
* {@link PropertyNamer PropertyNamers}, etc... which are used to tailor how POJOs are serialized and parsed.
*
*
*
* All serializers and parsers extend from this context so that they can handle POJOs using a common framework.
*
*
Bean Contexts
*
* Bean contexts are created through the {@link BeanContext#create() BeanContext.create()} and {@link BeanContextBuilder#build()} methods.
*
These context objects are read-only, reusable, and thread-safe.
*
*
* Each bean context maintains a cache of {@link ClassMeta} objects that describe information about classes encountered.
* These ClassMeta
objects are time-consuming to construct.
* Therefore, instances of {@link BeanContext} that share the same "BeanContext.*" property values share
* the same cache. This allows for efficient reuse of ClassMeta
objects so that the information about
* classes only needs to be calculated once.
* Because of this, many of the properties defined on the {@link BeanContext} class cannot be overridden on the session.
*
*
Bean Sessions
*
* Whereas BeanContext
objects are permanent, unchangeable, cached, and thread-safe,
* {@link BeanSession} objects are ephemeral and not thread-safe.
* They are meant to be used as quickly-constructed scratchpads for creating bean maps.
* {@link BeanMap} objects can only be created through the session.
*
* BeanContext configuration properties
*
* BeanContexts
have several configuration properties that can be used to tweak behavior on how beans are
* handled. These are denoted as the static BEAN_* fields on this class.
*
*
* Some settings (e.g. {@link #BEAN_beansRequireDefaultConstructor}) are used to differentiate between bean
* and non-bean classes.
* Attempting to create a bean map around one of these objects will throw a {@link BeanRuntimeException}.
* The purpose for this behavior is so that the serializers can identify these non-bean classes and convert them to
* plain strings using the {@link Object#toString()} method.
*
*
* Some settings (e.g. {@link #BEAN_beanFieldVisibility}) are used to determine what kinds of properties are
* detected on beans.
*
*
* Some settings (e.g. {@link #BEAN_beanMapPutReturnsOldValue}) change the runtime behavior of bean maps.
*
*
* Settings are specified using the {@link BeanContextBuilder#set(String, Object)} method and related convenience
* methods.
*
*
Example:
*
*
* // Construct a context from scratch.
* BeanContext beanContext = BeanContext
* .create ()
* .set(BeanContext.BEAN_beansRequireDefaultConstructor , true )
* .notBeanClasses(Foo.class )
* .build();
*
*
* Bean Maps
*
* {@link BeanMap BeanMaps} are wrappers around Java beans that allow properties to be retrieved and
* set using the common {@link Map#put(Object,Object)} and {@link Map#get(Object)} methods.
*
*
* Bean maps are created in two ways...
*
* - {@link BeanSession#toBeanMap(Object) BeanSession.toBeanMap()} - Wraps an existing bean inside a {@code Map}
* wrapper.
*
- {@link BeanSession#newBeanMap(Class) BeanSession.newBeanMap()} - Create a new bean instance wrapped in a
* {@code Map} wrapper.
*
*
* Example:
*
*
* // A sample bean class
* public class Person {
* public String getName();
* public void setName(String name);
* public int getAge();
* public void setAge(int age);
* }
*
* // Create a new bean session
* BeanSession session = BeanContext.DEFAULT .createSession();
*
* // Wrap an existing bean in a new bean map
* BeanMap<Person> m1 = session.toBeanMap(new Person());
* m1.put("name" , "John Smith" );
* m1.put("age" , 45);
*
* // Create a new bean instance wrapped in a new bean map
* BeanMap<Person> m2 = session.newBeanMap(Person.class );
* m2.put("name" , "John Smith" );
* m2.put("age" , 45);
* Person p = m2.getBean(); // Get the bean instance that was created.
*
*
* See Also:
*
* - {@doc juneau-marshall.ContextsBuildersSessionsPropertyStores}
*
*/
@SuppressWarnings({"unchecked","rawtypes"})
public class BeanContext extends Context {
static final String PREFIX = "BeanContext.";
/**
* Configuration property: Minimum bean class visibility.
*
* Property:
*
* - Name:
"BeanContext.beanClassVisibility.s"
* - Data type:
String
({@link Visibility})
* - Default:
"PUBLIC"
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beanClassVisibility(Visibility)}
*
*
*
* Description:
*
* 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 and be serialized as a string.
*
Use this setting to reduce the visibility requirement.
*
*
Example:
*
* // Create a serializer that serializes protected classes.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanClassVisibility(PROTECTED )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beanClassVisibility , "PROTECTED" )
* .build();
*
*/
public static final String BEAN_beanClassVisibility = PREFIX + "beanClassVisibility.s";
/**
* Configuration property: Minimum bean constructor visibility.
*
* Property:
*
* - Name:
"BeanContext.beanConstructorVisibility.s"
* - Data type:
String
({@link Visibility})
* - Default:
"PUBLIC"
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beanConstructorVisibility(Visibility)}
*
*
*
* Description:
*
* Only look for constructors with the specified minimum visibility.
*
*
* This setting affects the logic for finding no-arg constructors for bean.
*
Normally, only public no-arg constructors are used.
*
Use this setting if you want to reduce the visibility requirement.
*
*
Example:
*
* // Create a serializer that looks for protected no-arg constructors.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanConstructorVisibility(PROTECTED )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beanConstructorVisibility , "PROTECTED" )
* .build();
*
*/
public static final String BEAN_beanConstructorVisibility = PREFIX + "beanConstructorVisibility.s";
/**
* Configuration property: Bean dictionary.
*
* Property:
*
* - Name:
"BeanContext.beanDictionary.lc"
* - Data type:
List<Class>
* - Default: empty list
*
- Session property:
false
* - Annotations:
*
* - {@link Bean#beanDictionary()}
*
- {@link BeanProperty#beanDictionary()}
*
* - Methods:
*
* - {@link BeanContextBuilder#beanDictionary(Object...)}
*
- {@link BeanContextBuilder#beanDictionary(Class...)}
*
- {@link BeanContextBuilder#beanDictionary(boolean,Object...)}
*
- {@link BeanContextBuilder#beanDictionaryRemove(Object...)}
*
- {@link BeanFilterBuilder#beanDictionary(Class...)}
*
*
*
* Description:
*
* The list of classes that make up the bean dictionary in this bean context.
*
*
* A dictionary is a name/class mapping used to find class types during parsing when they cannot be inferred
* through reflection.
*
The names are defined through the {@link Bean#typeName() @Bean(typeName)} annotation defined on the bean class.
*
For example, if a class Foo
has a type-name of "myfoo" , then it would end up serialized
* as "{_type:'myfoo',...}" .
*
*
* This setting tells the parsers which classes to look for when resolving "_type" attributes.
*
*
* Values can consist of any of the following 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.
*
- Any array or collection of the objects above.
*
*
* Example:
*
* // Create a parser and tell it which classes to try to resolve.
* ReaderParser p = JsonParser
* .create ()
* .beanDictionary(Foo.class , Bar.class )
* .build();
*
* // Same, but use property.
* ReaderParser p = JsonParser
* .create ()
* .addTo(BEAN_beanDictionary , Foo.class )
* .addTo(BEAN_beanDictionary , Bar.class )
* .build();
*
* // Instead of by parser, define a bean dictionary on a class through an annotation.
* // This applies to all properties on this class and all subclasses.
* @Bean (beanDictionary={Foo.class ,Bar.class })
* public class MyBean {...}
*
* // Use the predefined HTML5 bean dictionary which is a BeanDictionaryList.
* ReaderParser p = HtmlParser
* .create ()
* .beanDictionary(HtmlBeanDictionary.class )
* .build();
*
*
* See Also:
*
* - {@doc juneau-marshall.BeanDictionaries}
*
*/
public static final String BEAN_beanDictionary = PREFIX + "beanDictionary.lc";
/**
* Configuration property: Add to bean dictionary.
*/
public static final String BEAN_beanDictionary_add = PREFIX + "beanDictionary.lc/add";
/**
* Configuration property: Remove from bean dictionary.
*/
public static final String BEAN_beanDictionary_remove = PREFIX + "beanDictionary.lc/remove";
/**
* Configuration property: Minimum bean field visibility.
*
* Property:
*
* - Name:
"BeanContext.beanFieldVisibility.s"
* - Data type:
String
({@link Visibility})
* - Default:
"PUBLIC"
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beanFieldVisibility(Visibility)}
*
*
*
* Description:
*
* Only look for bean fields with the specified minimum visibility.
*
*
* This affects which fields on a bean class are considered bean properties.
*
Normally only public fields are considered.
*
Use this setting if you want to reduce the visibility requirement.
*
*
Example:
*
* // Create a serializer that looks for protected fields.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanFieldVisibility(PROTECTED )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beanFieldVisibility , "PROTECTED" )
* .build();
*
* // Disable using fields as properties entirely.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanFieldVisibility(NONE )
* .build();
*
*/
public static final String BEAN_beanFieldVisibility = PREFIX + "beanFieldVisibility.s";
/**
* Configuration property: Bean filters.
*
* Property:
*
* - Name:
"BeanContext.beanFilters.lc"
* - Data type:
List<Class>
* - Default: empty list
*
- Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beanFilters(Object...)}
*
- {@link BeanContextBuilder#beanFilters(Class...)}
*
- {@link BeanContextBuilder#beanFilters(boolean,Object...)}
*
- {@link BeanContextBuilder#beanFiltersRemove(Object...)}
*
*
*
* Description:
*
* 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.
*
*
* Values can consist of any of the following types:
*
* - Any subclass of {@link BeanFilterBuilder}.
*
These must have a public no-arg constructor.
* - Any bean interfaces.
*
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.
* - Any array or collection of the objects above.
*
*
* Example:
*
* // Create a bean filter for the MyBean class.
* public class MyBeanFilter extends BeanFilterBuilder<MyBean> {
*
* // Must provide a no-arg constructor!
* public MyBeanFilter() {
* includeProperties("foo,bar,baz" ); // The properties we want exposed.
* }
* }
*
* // Associate our bean filter with a serializer.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanFilters(MyBeanFilter.class )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_beanFilters , MyBeanFilter.class )
* .build();
*
*
* See Also:
*
* - {@doc juneau-marshall.Transforms.BeanFilters}
*
- {@doc juneau-marshall.Transforms.InterfaceFilters}
*
*/
public static final String BEAN_beanFilters = PREFIX + "beanFilters.lc";
/**
* Configuration property: Add to bean filters.
*/
public static final String BEAN_beanFilters_add = PREFIX + "beanFilters.lc/add";
/**
* Configuration property: Remove from bean filters.
*/
public static final String BEAN_beanFilters_remove = PREFIX + "beanFilters.lc/remove";
/**
* Configuration property: BeanMap.put() returns old property value.
*
* Property:
*
* - Name:
"BeanContext.beanMapPutReturnsOldValue.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beanMapPutReturnsOldValue(boolean)}
*
- {@link BeanContextBuilder#beanMapPutReturnsOldValue()}
*
*
*
* Description:
*
* 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 during serialization.
*
*
Example:
*
* // Create a serializer that creates BeanMaps with normal put() behavior.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanMapPutReturnsOldValue()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beanMapPutReturnsOldValue , true )
* .build();
*
* BeanMap<MyBean> bm = s.createSession().toBeanMap(new MyBean());
* bm.put("foo" , "bar" );
* Object oldValue = bm.put("foo" , "baz" ); // oldValue == "bar"
*
*/
public static final String BEAN_beanMapPutReturnsOldValue = PREFIX + "beanMapPutReturnsOldValue.b";
/**
* Configuration property: Minimum bean method visibility.
*
* Property:
*
* - Name:
"BeanContext.beanMethodVisibility.s"
* - Data type:
String
({@link Visibility})
* - Default:
"PUBLIC"
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beanMethodVisibility(Visibility)}
*
*
*
* Description:
*
* Only look for bean methods with the specified minimum visibility.
*
*
* This affects which methods are detected as getters and setters on a bean class.
*
Normally only public getters and setters are considered.
*
Use this setting if you want to reduce the visibility requirement.
*
*
Example:
*
* // Create a serializer that looks for protected getters and setters.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanMethodVisibility(PROTECTED )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beanMethodVisibility , "PROTECTED" )
* .build();
*
*/
public static final String BEAN_beanMethodVisibility = PREFIX + "beanMethodVisibility.s";
/**
* Configuration property: Beans require no-arg constructors.
*
* Property:
*
* - Name:
"BeanContext.beansRequireDefaultConstructor.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beansRequireDefaultConstructor(boolean)}
*
- {@link BeanContextBuilder#beansRequireDefaultConstructor()}
*
*
*
* Description:
*
* 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 .
*
*
Example:
*
* // Create a serializer that ignores beans without default constructors.
* WriterSerializer s = JsonSerializer
* .create ()
* .beansRequireDefaultConstructor()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beansRequireDefaultConstructor , true )
* .build();
*
*/
public static final String BEAN_beansRequireDefaultConstructor = PREFIX + "beansRequireDefaultConstructor.b";
/**
* Configuration property: Beans require Serializable interface.
*
* Property:
*
* - Name:
"BeanContext.beansRequireSerializable.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beansRequireSerializable(boolean)}
*
- {@link BeanContextBuilder#beansRequireSerializable()}
*
*
*
* Description:
*
* 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 .
*
*
Example:
*
* // Create a serializer that ignores beans not implementing Serializable.
* WriterSerializer s = JsonSerializer
* .create ()
* .beansRequireSerializable()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beansRequireSerializable , true )
* .build();
*
*/
public static final String BEAN_beansRequireSerializable = PREFIX + "beansRequireSerializable.b";
/**
* Configuration property: Beans require setters for getters.
*
* Property:
*
* - Name:
"BeanContext.beansRequireSettersForGetters.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beansRequireSettersForGetters(boolean)}
*
- {@link BeanContextBuilder#beansRequireSettersForGetters()}
*
*
*
* Description:
*
* If true , only getters that have equivalent setters will be considered as properties on a bean.
*
Otherwise, they will be ignored.
*
*
Example:
*
* // Create a serializer that ignores bean properties without setters.
* WriterSerializer s = JsonSerializer
* .create ()
* .beansRequireSettersForGetter()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beansRequireSettersForGetters , true )
* .build();
*
*/
public static final String BEAN_beansRequireSettersForGetters = PREFIX + "beansRequireSettersForGetters.b";
/**
* Configuration property: Beans require at least one property.
*
* Property:
*
* - Name:
"BeanContext.beansRequireSomeProperties.b"
* - Data type:
Boolean
* - Default:
true
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#beansRequireSomeProperties(boolean)}
*
*
*
* Description:
*
* 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 .
*
*
Example:
*
* // Create a serializer that serializes beans even if they have zero properties.
* WriterSerializer s = JsonSerializer
* .create ()
* .beansRequireSomeProperties(false )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beansRequireSomeProperties , false )
* .build();
*
*/
public static final String BEAN_beansRequireSomeProperties = PREFIX + "beansRequireSomeProperties.b";
/**
* Configuration property: Bean type property name.
*
* Property:
*
* - Name:
"BeanContext.beanTypePropertyName.s"
* - Data type:
String
* - Default:
"_type"
* - Session property:
false
* - Annotations:
*
* - {@link Bean#typePropertyName()}
*
* - Methods:
*
* - {@link BeanContextBuilder#beanTypePropertyName(String)}
*
*
*
*
* This specifies the name of the bean property used to store the dictionary name of a bean type so that the
* parser knows the data type to reconstruct.
*
*
Example:
*
* // Create a serializer that uses 'type' instead of '_type' for dictionary names.
* WriterSerializer s = JsonSerializer
* .create ()
* .beanTypePropertyName("type" )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_beanTypePropertyName , "type" )
* .build();
*
*
* See Also:
*
* - {@doc juneau-marshall.BeanDictionaries}
*
*/
public static final String BEAN_beanTypePropertyName = PREFIX + "beanTypePropertyName.s";
/**
* Configuration property: Debug mode.
*
* Property:
*
* - Name:
"BeanContext.debug.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
true
* - Methods:
*
* - {@link BeanContextBuilder#debug(boolean)}
*
- {@link BeanContextBuilder#debug()}
*
- {@link BeanSessionArgs#debug(Boolean)}
*
*
*
* Description:
*
* 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#BEANTRAVERSE_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.
*
*
* Example:
*
* // Create a serializer with debug enabled.
* WriterSerializer s = JsonSerializer
* .create ()
* .debug()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_debug , true )
* .build();
*
*/
public static final String BEAN_debug = PREFIX + "debug.b";
/**
* Configuration property: POJO examples.
*
* Property:
*
* - Name:
"BeanContext.examples.smo"
* - Data type:
Map<String,Object>
* - Default:
{}
* - Session property:
false
* - Annotations:
*
* - {@link Example}
*
* - Methods:
*
* - {@link BeanContextBuilder#example(Class,Object)}
*
*
*
* Description:
*
* Specifies an example of the specified class.
*
*
* Examples are used in cases such as POJO examples in Swagger documents.
*
*
* Setting applies to specified class and all subclasses.
*
*
Example:
*
* // Create a serializer that excludes the 'foo' and 'bar' properties on the MyBean class.
* WriterSerializer s = JsonSerializer
* .create ()
* .example(MyBean.class , new MyBean().foo("foo" ).bar(123))
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_examples , MyBean.class .getName(), new MyBean().foo("foo" ).bar(123))
* .build();
*
*
*
* POJO examples can also be defined on classes via the following:
*
* - A static field annotated with {@link Example @Example}.
*
- A static method annotated with {@link Example @Example} with zero arguments or one {@link BeanSession} argument.
*
- A static method with name
example
with no arguments or one {@link BeanSession} argument.
*
*/
public static final String BEAN_examples = PREFIX + "examples.smo";
/**
* Configuration property: Bean property excludes.
*
* Property:
*
* - Name:
"BeanContext.excludeProperties.sms"
* - Data type:
Map<String,String>
* - Default:
{}
* - Session property:
false
* - Annotations:
*
* - {@link Bean#excludeProperties()}
*
* - Methods:
*
* - {@link BeanContextBuilder#excludeProperties(Class, String)}
*
- {@link BeanContextBuilder#excludeProperties(String, String)}
*
- {@link BeanContextBuilder#excludeProperties(Map)}
*
- {@link BeanFilterBuilder#excludeProperties(String...)}
*
*
*
* Description:
*
* Specifies to exclude the specified list of properties for the specified bean class.
*
*
* 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 any beans whose simple class name is Bean1
.
*
*
* Setting applies to specified class and all subclasses.
*
*
Example:
*
* // Create a serializer that excludes the 'foo' and 'bar' properties on the MyBean class.
* WriterSerializer s = JsonSerializer
* .create ()
* .excludeProperties(MyBean.class , "foo,bar" )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_excludeProperties , MyBean.class .getName(), "foo,bar" )
* .build();
*
* // Alternate using JSON object.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_excludeProperties , "{'org.apache.MyBean':'foo,bar'}" )
* .build();
*
*/
public static final String BEAN_excludeProperties = PREFIX + "excludeProperties.sms";
/**
* Configuration property: Find fluent setters.
*
* Property:
*
* - Name:
"BeanContext.fluentSetters.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Annotations:
*
* - {@link Bean#fluentSetters()}
*
* - Methods:
*
* - {@link BeanContextBuilder#fluentSetters(boolean)}
*
- {@link BeanContextBuilder#fluentSetters()}
*
- {@link BeanFilterBuilder#fluentSetters(boolean)}
*
- {@link BeanFilterBuilder#fluentSetters()}
*
*
*
* Description:
*
* When enabled, fluent setters are detected on beans.
*
*
* Fluent setters must have the following attributes:
*
* - Public.
*
- Not static.
*
- Take in one parameter.
*
- Return the bean itself.
*
*
* Example:
*
* // Create a serializer that finds fluent setters.
* WriterSerializer s = JsonSerializer
* .create ()
* .fluentSetters()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_fluentSetters , true )
* .build();
*
*/
public static final String BEAN_fluentSetters = PREFIX + "fluentSetters.b";
/**
* Configuration property: Ignore invocation errors on getters.
*
* Property:
*
* - Name:
"BeanContext.ignoreInvocationExceptionsOnGetters.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#ignoreInvocationExceptionsOnGetters(boolean)}
*
- {@link BeanContextBuilder#ignoreInvocationExceptionsOnGetters()}
*
*
*
* Description:
*
* If true , errors thrown when calling bean getter methods will silently be ignored.
*
Otherwise, a {@code BeanRuntimeException} is thrown.
*
*
Example:
*
* // Create a serializer that ignores bean getter exceptions.
* WriterSerializer s = JsonSerializer
* .create ()
* .ingoreInvocationExceptionsOnGetters()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_ignoreInvocationExceptionsOnGetters , true )
* .build();
*
*/
public static final String BEAN_ignoreInvocationExceptionsOnGetters = PREFIX + "ignoreInvocationExceptionsOnGetters.b";
/**
* Configuration property: Ignore invocation errors on setters.
*
* Property:
*
* - Name:
"BeanContext.ignoreInvocationExceptionsOnSetters.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#ignoreInvocationExceptionsOnSetters(boolean)}
*
- {@link BeanContextBuilder#ignoreInvocationExceptionsOnSetters()}
*
*
*
* Description:
*
* If true , errors thrown when calling bean setter methods will silently be ignored.
*
Otherwise, a {@code BeanRuntimeException} is thrown.
*
*
Example:
*
* // Create a parser that ignores bean setter exceptions.
* ReaderParser p = JsonParser
* .create ()
* .ignoreInvocationExceptionsOnSetters()
* .build();
*
* // Same, but use property.
* ReaderParser p = JsonParser
* .create ()
* .set(BEAN_ignoreInvocationExceptionsOnSetters , true )
* .build();
*
*/
public static final String BEAN_ignoreInvocationExceptionsOnSetters = PREFIX + "ignoreInvocationExceptionsOnSetters.b";
/**
* Configuration property: Ignore properties without setters.
*
* Property:
*
* - Name:
"BeanContext.ignorePropertiesWithoutSetters.b"
* - Data type:
Boolean
* - Default:
true
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#ignorePropertiesWithoutSetters(boolean)}
*
*
*
* Description:
*
* If true , trying to set a value on a bean property without a setter will silently be ignored.
*
Otherwise, a {@code RuntimeException} is thrown.
*
*
Example:
*
* // Create a parser that throws an exception if a setter is not found but a getter is.
* ReaderParser p = JsonParser
* .create ()
* .ignorePropertiesWithoutSetters(false )
* .build();
*
* // Same, but use property.
* ReaderParser p = JsonParser
* .create ()
* .set(BEAN_ignorePropertiesWithoutSetters , false )
* .build();
*
*/
public static final String BEAN_ignorePropertiesWithoutSetters = PREFIX + "ignorePropertiesWithoutSetters.b";
/**
* Configuration property: Ignore unknown properties.
*
* Property:
*
* - Name:
"BeanContext.ignoreUnknownBeanProperties.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#ignoreUnknownBeanProperties(boolean)}
*
- {@link BeanContextBuilder#ignoreUnknownBeanProperties()}
*
*
*
* Description:
*
* If true , trying to set a value on a non-existent bean property will silently be ignored.
*
Otherwise, a {@code RuntimeException} is thrown.
*
*
Example:
*
* // Create a parser that ignores missing bean properties.
* ReaderParser p = JsonParser
* .create ()
* .ignoreUnknownBeanProperties()
* .build();
*
* // Same, but use property.
* ReaderParser p = JsonParser
* .create ()
* .set(BEAN_ignoreUnknownBeanProperties , true )
* .build();
*
*/
public static final String BEAN_ignoreUnknownBeanProperties = PREFIX + "ignoreUnknownBeanProperties.b";
/**
* Configuration property: Ignore unknown properties with null values.
*
* Property:
*
* - Name:
"BeanContext.ignoreUnknownNullBeanProperties.b"
* - Data type:
Boolean
* - Default:
true
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#ignoreUnknownNullBeanProperties(boolean)}
*
*
*
* Description:
*
* If true , trying to set a null value on a non-existent bean property will silently be ignored.
*
Otherwise, a {@code RuntimeException} is thrown.
*
*
Example:
*
* // Create a parser that throws an exception on an unknown property even if the value being set is null.
* ReaderParser p = JsonParser
* .create ()
* .ignoreUnknownNullBeanProperties(false )
* .build();
*
* // Same, but use property.
* ReaderParser p = JsonParser
* .create ()
* .set(BEAN_ignoreUnknownNullBeanProperties , false )
* .build();
*
*/
public static final String BEAN_ignoreUnknownNullBeanProperties = PREFIX + "ignoreUnknownNullBeanProperties.b";
/**
* Configuration property: Implementation classes.
*
* Property:
*
* - Name:
"BeanContext.implClasses.smc"
* - Data type:
Map<String,Class>
* - Default: empty map
*
- Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#implClasses(Map)}
*
- {@link BeanContextBuilder#implClass(Class, Class)}
*
*
*
* Description:
*
* 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).
*
*
Example:
*
* // Create a parser that instantiates MyBeanImpls when parsing MyBeanInterfaces.
* ReaderParser p = JsonParser
* .create ()
* .implClass(MyBeanInterface.class , MyBeanImpl.class )
* .build();
*
* // Same, but use property.
* ReaderParser p = JsonParser
* .create ()
* .addTo(BEAN_implClasses , MyBeanInterface.class .getName(), MyBeanImpl.class )
* .build();
*
*/
public static final String BEAN_implClasses = PREFIX + "implClasses.smc";
/**
* Configuration property: Bean property includes.
*
* Property:
*
* - Name:
"BeanContext.properties.sms"
* - Data type:
Map<String,String>
* - Default:
{}
* - Session property:
false
* - Annotations:
*
* - {@link Bean#properties()}
*
- {@link BeanProperty#properties()}
*
* - Methods:
*
* - {@link BeanContextBuilder#includeProperties(Class, String)}
*
- {@link BeanContextBuilder#includeProperties(String, String)}
*
- {@link BeanContextBuilder#includeProperties(Map)}
*
- {@link BeanFilterBuilder#properties(String...)}
*
*
*
* Description:
*
* Specifies the set and order of names of properties associated with the bean class.
*
*
* 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.
*
*
* Setting applies to specified class and all subclasses.
*
*
Example:
*
* // Create a serializer that includes only the 'foo' and 'bar' properties on the MyBean class.
* WriterSerializer s = JsonSerializer
* .create ()
* .includeProperties(MyBean.class , "foo,bar" )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_includeProperties , MyBean.class .getName(), "foo,bar" )
* .build();
*
* // Alternate using JSON object.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_includeProperties , "{'org.apache.MyBean':'foo,bar'}" )
* .build();
*
*/
public static final String BEAN_includeProperties = PREFIX + "includeProperties.sms";
/**
* Configuration property: Locale.
*
* Property:
*
* - Name:
"BeanContext.locale.s"
* - Data type:
String
({@link Locale})
* - Default:
null (defaults to {@link Locale#getDefault()})
* - Session property:
true
* - Methods:
*
* - {@link BeanContextBuilder#locale(Locale)}
*
- {@link BeanSessionArgs#locale(Locale)}
*
*
*
* Description:
*
* Specifies the default locale for serializer and parser sessions.
*
*
Example:
*
* // Create a serializer that uses the specified locale if it's not passed in through session args.
* WriterSerializer s = JsonSerializer
* .create ()
* .locale(Locale.UK )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_locale , Locale.UK )
* .build();
*
* // Define on session-args instead.
* SerializerSessionArgs sessionArgs = new SerializerSessionArgs().locale(Locale.UK );
* try (WriterSerializerSession session = s.createSession(sessionArgs)) {
* ...
* }
*
*/
public static final String BEAN_locale = PREFIX + "locale.s";
/**
* Configuration property: Media type.
*
* Property:
*
* - Name:
"BeanContext.mediaType.s"
* - Data type:
String
({@link MediaType})
* - Default:
null
* - Session property:
true
* - Methods:
*
* - {@link BeanContextBuilder#mediaType(MediaType)}
*
- {@link BeanSessionArgs#mediaType(MediaType)}
*
*
*
* Description:
*
* Specifies the default media type value for serializer and parser sessions.
*
*
Example:
*
* // Create a serializer that uses the specified media type if it's not passed in through session args.
* WriterSerializer s = JsonSerializer
* .create ()
* .mediaType(MediaType.JSON )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_mediaType , MediaType.JSON )
* .build();
*
* // Define on session-args instead.
* SerializerSessionArgs sessionArgs = new SerializerSessionArgs().mediaType(MediaType.JSON );
* try (WriterSerializerSession session = s.createSession(sessionArgs)) {
* ...
* }
*
*/
public static final String BEAN_mediaType = PREFIX + "mediaType.s";
/**
* Configuration property: Bean class exclusions.
*
* Property:
*
* - Name:
"BeanContext.notBeanClasses.sc"
* - Data type:
Set<Class>
* - Default: empty set
*
- Session property:
false
* - Annotations:
*
* - {@link BeanIgnore}
*
* - Methods:
*
* - {@link BeanContextBuilder#notBeanClasses(Class...)}
*
- {@link BeanContextBuilder#notBeanClasses(Object...)}
*
- {@link BeanContextBuilder#notBeanClasses(boolean, Object...)}
*
- {@link BeanContextBuilder#notBeanClassesRemove(Object...)}
*
*
*
* Description:
*
* List of classes that should not be treated as beans even if they appear to be bean-like.
*
Not-bean classes are converted to Strings
during serialization.
*
*
* Values can consist of any of the following types:
*
* - Classes.
*
- Arrays and collections of classes.
*
*
* Example:
*
* // Create a serializer that doesn't treat MyBean as a bean class.
* WriterSerializer s = JsonSerializer
* .create ()
* .notBeanClasses(MyBean.class )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_notBeanClasses , MyBean.class )
* .build();
*
*/
public static final String BEAN_notBeanClasses = PREFIX + "notBeanClasses.sc";
/**
* Configuration property: Add to classes that should not be considered beans.
*/
public static final String BEAN_notBeanClasses_add = PREFIX + "notBeanClasses.sc/add";
/**
* Configuration property: Remove from classes that should not be considered beans.
*/
public static final String BEAN_notBeanClasses_remove = PREFIX + "notBeanClasses.sc/remove";
/**
* Configuration property: Bean package exclusions.
*
* Property:
*
* - Name:
"BeanContext.notBeanPackages.ss"
* - 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 property:
false
* - Methods:
*
* - {@link BeanContextBuilder#notBeanPackages(Object...)}
*
- {@link BeanContextBuilder#notBeanPackages(String...)}
*
- {@link BeanContextBuilder#notBeanPackages(boolean, Object...)}
*
- {@link BeanContextBuilder#notBeanPackagesRemove(Object...)}
*
*
*
* Description:
*
* 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 suffix patterns to include all subpackages.
*
*
* Values can consist of any of the following types:
*
* - Strings.
*
- Arrays and collections of strings.
*
*
* Example:
*
* // Create a serializer that ignores beans in the specified packages.
* WriterSerializer s = JsonSerializer
* .create ()
* .notBeanPackages("org.apache.foo" , "org.apache.bar.*" )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_notBeanPackages , "org.apache.foo" )
* .addTo(BEAN_notBeanPackages , "org.apache.bar.*" )
* .build();
*
*/
public static final String BEAN_notBeanPackages = PREFIX + "notBeanPackages.ss";
/**
* Configuration property: Add to packages whose classes should not be considered beans.
*/
public static final String BEAN_notBeanPackages_add = PREFIX + "notBeanPackages.ss/add";
/**
* Configuration property: Remove from packages whose classes should not be considered beans.
*/
public static final String BEAN_notBeanPackages_remove = PREFIX + "notBeanPackages.ss/remove";
/**
* Configuration property: POJO swaps.
*
* Property:
*
* - Name:
"BeanContext.pojoSwaps.lo"
* - Data type:
List<Object>
* - Default: empty list
*
- Session property:
false
* - Annotations:
*
* - {@link Swap}
*
- {@link Swaps}
*
* - Methods:
*
* - {@link BeanContextBuilder#pojoSwaps(Object...)}
*
- {@link BeanContextBuilder#pojoSwaps(Class...)}
*
- {@link BeanContextBuilder#pojoSwaps(boolean, Object...)}
*
- {@link BeanContextBuilder#pojoSwapsRemove(Object...)}
*
*
*
* Description:
*
* POJO swaps are used to "swap out" non-serializable classes with serializable equivalents during serialization,
* and "swap in" the non-serializable class during parsing.
*
*
* An example of a POJO swap would be a Calendar
object that gets swapped out for an ISO8601 string.
*
*
* Multiple POJO swaps can be associated with a single class.
*
When multiple swaps are applicable to the same class, the media type pattern defined by
* {@link PojoSwap#forMediaTypes()} or {@link Swap#mediaTypes() @Swap(mediaTypes)} are used to come up with the best match.
*
*
* Values can consist of any of the following types:
*
* - Any subclass of {@link PojoSwap}.
*
- Any instance of {@link PojoSwap}.
*
- Any surrogate class. A shortcut for defining a {@link SurrogateSwap}.
*
- Any array or collection of the objects above.
*
*
* Example:
*
* // Sample swap for converting Dates to ISO8601 strings.
* public class MyDateSwap extends StringSwap<Date> {
* // ISO8601 formatter.
* private DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ" );
*
* @Override
* public String swap(BeanSession session, Date o) {
* return format .format(o);
* }
*
* @Override
* public Date unswap(BeanSession session, String o, ClassMeta hint) throws Exception {
* return format .parse(o);
* }
* }
*
* // Sample bean with a Date field.
* public class MyBean {
* public Date date = new Date(112, 2, 3, 4, 5, 6);
* }
*
* // Create a serializer that uses our date swap.
* WriterSerializer s = JsonSerializer
* .create ()
* .pojoSwaps(MyDateSwap.class )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .addTo(BEAN_pojoSwaps , MyDateSwap.class )
* .build();
*
* // Produces "{date:'2012-03-03T04:05:06-0500'}"
* String json = s.serialize(new MyBean());
*
* // Create a serializer that uses our date swap.
* ReaderParser p = JsonParser
* .create ()
* .pojoSwaps(MyDateSwap.class )
* .build();
*
* // Use our parser to parse a bean.
* MyBean bean = p.parse(json, MyBean.class );
*
*
* See Also:
*
* - {@doc juneau-marshall.Transforms.PojoSwaps}
*
- {@doc juneau-marshall.Transforms.PerMediaTypePojoSwaps}
*
- {@doc juneau-marshall.Transforms.OneWayPojoSwaps}
*
- {@doc juneau-marshall.Transforms.SwapAnnotation}
*
- {@doc juneau-marshall.Transforms.SwapMethods}
*
- {@doc juneau-marshall.Transforms.SurrogateClasses}
*
*/
public static final String BEAN_pojoSwaps = PREFIX + "pojoSwaps.lo";
/**
* Configuration property: Add to POJO swap classes.
*/
public static final String BEAN_pojoSwaps_add = PREFIX + "pojoSwaps.lo/add";
/**
* Configuration property: Remove from POJO swap classes.
*/
public static final String BEAN_pojoSwaps_remove = PREFIX + "pojoSwaps.lo/remove";
/**
* Configuration property: Bean property namer.
*
* Property:
*
* - Name:
"BeanContext.propertyNamer.c"
* - Data type:
Class<? implements {@link PropertyNamer}>
* - Default: {@link PropertyNamerDefault}
*
- Session property:
false
* - Annotations:
*
* - {@link Bean#propertyNamer()}
*
* - Methods:
*
* - {@link BeanContextBuilder#propertyNamer(Class)}
*
- {@link BeanFilterBuilder#propertyNamer(Class)}
*
*
*
* Description:
*
* The class to use for calculating bean property names.
*
*
* Predefined classes:
*
* - {@link PropertyNamerDefault} - Default.
*
- {@link PropertyNamerDLC} - Dashed-lower-case names.
*
- {@link PropertyNamerULC} - Dashed-upper-case names.
*
*
* Example:
*
* // Create a serializer that uses Dashed-Lower-Case property names.
* // (e.g. "foo-bar-url" instead of "fooBarURL")
* WriterSerializer s = JsonSerializer
* .create ()
* .propertyNamer(PropertyNamerDLC.class )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_propertyNamer , PropertyNamerDLC.class )
* .build();
*
*/
public static final String BEAN_propertyNamer = PREFIX + "propertyNamer.c";
/**
* Configuration property: Sort bean properties.
*
* Property:
*
* - Name:
"BeanContext.sortProperties.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Annotations:
*
* - {@link Bean#sort()}
*
* - Methods:
*
* - {@link BeanContextBuilder#sortProperties(boolean)}
*
- {@link BeanContextBuilder#sortProperties()}
*
- {@link BeanFilterBuilder#sortProperties(boolean)}
*
- {@link BeanFilterBuilder#sortProperties()}
*
*
*
* Description:
*
* 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).
*
*
* 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.
*
*
Example:
*
* // Create a serializer that sorts bean properties.
* WriterSerializer s = JsonSerializer
* .create ()
* .sortProperties()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_sortProperties , true )
* .build();
*
*/
public static final String BEAN_sortProperties = PREFIX + "sortProperties.b";
/**
* Configuration property: Time zone.
*
* Property:
*
* - Name:
"BeanContext.timeZone.s"
* - Data type:
String
({@link TimeZone})
* - Default:
null
* - Session property:
true
* - Methods:
*
* - {@link BeanContextBuilder#timeZone(TimeZone)}
*
- {@link BeanSessionArgs#timeZone(TimeZone)}
*
*
*
* Description:
*
* Specifies the default timezone for serializer and parser sessions.
*
*
Example:
*
* // Create a serializer that uses GMT if the timezone is not specified in the session args.
* WriterSerializer s = JsonSerializer
* .create ()
* .timeZone(TimeZone.GMT )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_timeZone , TimeZone.GMT )
* .build();
*
* // Define on session-args instead.
* SerializerSessionArgs sessionArgs = new SerializerSessionArgs().timeZone(TimeZone.GMT );
* try (WriterSerializerSession ss = JsonSerializer.DEFAULT .createSession(sessionArgs)) {
* String json = s.serialize(new MyBean());
* }
*
*/
public static final String BEAN_timeZone = PREFIX + "timeZone.s";
/**
* Configuration property: Use enum names.
*
* Property:
*
* - Name:
"BeanContext.useEnumNames.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#useEnumNames()}
*
*
*
* Description:
*
* When enabled, enums are always serialized by name, not using {@link Object#toString()}.
*
*
Example:
*
* // Create a serializer with debug enabled.
* WriterSerializer s = JsonSerializer
* .create ()
* .useEnumNames()
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_useEnumNames , true )
* .build();
*
* // Enum with overridden toString().
* // Will be serialized as ONE/TWO/THREE even though there's a toString() method..
* public enum Option {
* ONE (1),
* TWO (2),
* THREE (3);
*
* private int i ;
*
* Option(int i) {
* this .i = i;
* }
*
* @Override
* public String toString() {
* return String.valueOf (i );
* }
*
*/
public static final String BEAN_useEnumNames = PREFIX + "useEnumNames.b";
/**
* Configuration property: Use interface proxies.
*
* Property:
*
* - Name:
"BeanContext.useInterfaceProxies.b"
* - Data type:
Boolean
* - Default:
true
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#useInterfaceProxies(boolean)}
*
*
*
* Description:
*
* 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.
*
Otherwise, throws a {@link BeanRuntimeException}.
*
*
Example:
*
* // Create a parser that doesn't try to make interface proxies.
* ReaderParser p = JsonParser
* .create ()
* .useInterfaceProxies(false )
* .build();
*
* // Same, but use property.
* ReaderParser p = JsonParser
* .create ()
* .set(BEAN_useInterfaceProxies , false )
* .build();
*
*/
public static final String BEAN_useInterfaceProxies = PREFIX + "useInterfaceProxies.b";
/**
* Configuration property: Use Java Introspector.
*
* Property:
*
* - Name:
"BeanContext.useJavaBeanIntrospector.b"
* - Data type:
Boolean
* - Default:
false
* - Session property:
false
* - Methods:
*
* - {@link BeanContextBuilder#useJavaBeanIntrospector(boolean)}
*
- {@link BeanContextBuilder#useJavaBeanIntrospector()}
*
*
*
* Description:
*
* Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters.
*
Most {@link Bean @Bean} annotations will be ignored.
*
*
Example:
*
* // Create a serializer that only uses the built-in java bean introspector for finding properties.
* WriterSerializer s = JsonSerializer
* .create ()
* .useJavaBeanIntrospector(false )
* .build();
*
* // Same, but use property.
* WriterSerializer s = JsonSerializer
* .create ()
* .set(BEAN_useJavaBeanIntrospector , false )
* .build();
*
*/
public static final String BEAN_useJavaBeanIntrospector = PREFIX + "useJavaBeanIntrospector.b";
/*
* The default package pattern exclusion list.
* Any beans in packages in this list will not be considered beans.
*/
private static final String[] DEFAULT_NOTBEAN_PACKAGES = {
"java.lang",
"java.lang.annotation",
"java.lang.ref",
"java.lang.reflect",
"java.io",
"java.net",
"java.nio.*",
"java.util.*"
};
/*
* The default bean class exclusion list.
* Anything in this list will not be considered beans.
*/
private static final Class>[] DEFAULT_NOTBEAN_CLASSES = {
Map.class,
Collection.class,
Reader.class,
Writer.class,
InputStream.class,
OutputStream.class,
Throwable.class
};
// This map is important!
// We may have many Context objects that have identical BeanContext properties.
// This map ensures that if the BeanContext properties in the Context are the same,
// then we reuse the same Class->ClassMeta cache map.
// This significantly reduces the number of times we need to construct ClassMeta objects which can be expensive.
private static final ConcurrentHashMap> cmCacheCache
= new ConcurrentHashMap<>();
/** Default config. All default settings. */
public static final BeanContext DEFAULT = BeanContext.create().build();
/** Default config. All default settings except sort bean properties. */
public static final BeanContext DEFAULT_SORTED = BeanContext.create().sortProperties().build();
private final boolean
beansRequireDefaultConstructor,
beansRequireSerializable,
beansRequireSettersForGetters,
beansRequireSomeProperties,
beanMapPutReturnsOldValue,
useInterfaceProxies,
ignoreUnknownBeanProperties,
ignoreUnknownNullBeanProperties,
ignorePropertiesWithoutSetters,
ignoreInvocationExceptionsOnGetters,
ignoreInvocationExceptionsOnSetters,
useJavaBeanIntrospector,
useEnumNames,
sortProperties,
fluentSetters,
debug;
private final Visibility
beanConstructorVisibility,
beanClassVisibility,
beanMethodVisibility,
beanFieldVisibility;
private final Class>[] notBeanClasses;
private final List> beanDictionaryClasses;
private final String[] notBeanPackageNames, notBeanPackagePrefixes;
private final BeanFilter[] beanFilters;
private final PojoSwap,?>[] pojoSwaps;
private final Map examples;
private final BeanRegistry beanRegistry;
private final Map> implClasses;
private final Locale locale;
private final TimeZone timeZone;
private final MediaType mediaType;
private final Map includeProperties, excludeProperties;
private final PropertyNamer propertyNamer;
private final String beanTypePropertyName;
private final int beanHashCode;
final Map cmCache;
private final ClassMeta