Class MarshallingContext.Builder
- Enclosing class:
- MarshallingContext
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor.protectedBuilder(MarshallingContext copyFrom) Copy constructor.protectedBuilder(MarshallingContext.Builder copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionactiveView(String value) Sets the default active view name for all sessions created from this context.beanClassVisibility(Visibility value) Minimum bean class visibility.Minimum bean constructor visibility.Returns the bean dictionary list.beanDictionary(Class<?>... values) Convenience method forbeanDictionary(ClassInfo...)that acceptsClassobjects.beanDictionary(Collection<ClassInfo> values) Same asbeanDictionary(ClassInfo...)but allows you to pass in a collection of class info objects.beanDictionary(ClassInfo... values) Bean dictionary.beanFieldVisibility(Visibility value) Minimum bean field visibility.beanInterceptor(Class<?> on, Class<? extends BeanInterceptor<?>> value) Bean interceptor.BeanMap.put() returns old property value.beanMapPutReturnsOldValue(boolean value) Same asbeanMapPutReturnsOldValue()but allows you to explicitly specify the value.beanMethodVisibility(Visibility value) Minimum bean method visibility.beanProperties(Class<?> beanClass, String properties) Bean property includes.beanProperties(String beanClassName, String properties) Bean property includes.beanProperties(Map<String, Object> values) Bean property includes.beanPropertiesExcludes(Class<?> beanClass, String properties) Bean property excludes.beanPropertiesExcludes(String beanClassName, String properties) Bean property excludes.beanPropertiesExcludes(Map<String, Object> values) Bean property excludes.beanPropertiesReadOnly(Class<?> beanClass, String properties) Read-only bean properties.beanPropertiesReadOnly(String beanClassName, String properties) Read-only bean properties.beanPropertiesReadOnly(Map<String, Object> values) Read-only bean properties.beanPropertiesWriteOnly(Class<?> beanClass, String properties) Write-only bean properties.beanPropertiesWriteOnly(String beanClassName, String properties) Write-only bean properties.beanPropertiesWriteOnly(Map<String, Object> values) Write-only bean properties.Beans require no-arg constructors.beansRequireDefaultConstructor(boolean value) Same asbeansRequireDefaultConstructor()but allows you to explicitly specify the value.Beans require Serializable interface.beansRequireSerializable(boolean value) Same asbeansRequireSerializable()but allows you to explicitly specify the value.Beans require setters for getters.beansRequireSettersForGetters(boolean value) Same asbeansRequireSettersForGetters()but allows you to explicitly specify the value.Sets the bean store used for factory-based instantiation.bigNumberFormat(BigNumberFormat value) Big-number wire format.binaryFormat(BinaryFormat value) Binary wire format.bitSetFormat(BitSetFormat value) BitSet wire format.booleanFormat(BooleanFormat value) Boolean wire format.build()Build the object.calendarFormat(CalendarFormat value) Calendar wire format.classFormat(ClassFormat value) Class wire format.classLoader(ClassLoader value) Session classloader.copy()Copy creator.static MarshallingContext.BuilderNull-safe copy: returns a deep copy of the specified value, ornull if the value isnull .currencyFormat(CurrencyFormat value) Currency wire format.dateFormat(DateFormat value) Date wire format.dictionaryOn(Class<?> on, Class<?>... values) Bean dictionary.Beans don't require at least one property.disableBeansRequireSomeProperties(boolean value) Same asdisableBeansRequireSomeProperties()but allows you to explicitly specify the value.Disables the default-view-inclusion policy.disableDefaultViewInclusion(boolean value) Same asdisableDefaultViewInclusion()but allows you to explicitly specify the value.Don't silently ignore missing setters.disableIgnoreMissingSetters(boolean value) Same asdisableIgnoreMissingSetters()but allows you to explicitly specify the value.Don't ignore transient fields.disableIgnoreTransientFields(boolean value) Same asdisableIgnoreTransientFields()but allows you to explicitly specify the value.Don't ignore unknown properties with null values.disableIgnoreUnknownNullBeanProperties(boolean value) Same asdisableIgnoreUnknownNullBeanProperties()but allows you to explicitly specify the value.Don't use interface proxies.disableInterfaceProxies(boolean value) Same asdisableInterfaceProxies()but allows you to explicitly specify the value.durationFormat(DurationFormat value) Duration wire format.enumFormat(EnumFormat value) Enum wire format.POJO example.POJO example.Find fluent setters.findFluentSetters(boolean value) Same asfindFluentSetters()but allows you to explicitly specify the value.findFluentSetters(Class<?> on) Find fluent setters.floatFormat(FloatFormat value) Float / Double non-finite wire format.hashKey()Returns the hashkey of this builder.Ignore invocation errors on getters.ignoreInvocationExceptionsOnGetters(boolean value) Same asignoreInvocationExceptionsOnGetters()but allows you to explicitly specify the value.Ignore invocation errors on setters.ignoreInvocationExceptionsOnSetters(boolean value) Same asignoreInvocationExceptionsOnSetters()but allows you to explicitly specify the value.Ignore unknown properties.ignoreUnknownBeanProperties(boolean value) Same asignoreUnknownBeanProperties()but allows you to explicitly specify the value.Ignore unknown properties.ignoreUnknownEnumValues(boolean value) Same asignoreUnknownEnumValues()but allows you to explicitly specify the value.Implementation classes.implClasses(Map<Class<?>, Class<?>> values) Implementation classes.interfaceClass(Class<?> on, Class<?> value) Identifies a class to be used as the interface class for the specified class and all subclasses.interfaces(Class<?>... value) Identifies a set of interfaces.Context configuration property: Locale.localeFormat(LocaleFormat value) Locale wire format.Context configuration property: Media type.Returns the set of not-bean classes.notBeanClasses(Class<?>... values) Convenience method fornotBeanClasses(ClassInfo...)that acceptsClassobjects.notBeanClasses(Collection<ClassInfo> values) Same asnotBeanClasses(ClassInfo...)but allows you to pass in a collection of class info objects.notBeanClasses(ClassInfo... values) Bean class exclusions.Returns the list of not-bean Java package names.notBeanPackages(String... values) Bean package exclusions.notBeanPackages(Collection<String> values) Same asnotBeanPackages(String...)but allows you to pass in a collection of classes.periodFormat(PeriodFormat value) Period wire format.propertyNamer(Class<?> on, Class<? extends PropertyNamer> value) Bean property namerpropertyNamer(Class<? extends PropertyNamer> value) Bean property namerUse record component order forRecordbeans.recordComponentOrder(boolean value) Same asrecordComponentOrder()but allows you to explicitly specify the value.Identifies a stop class for the annotated class.<T,S> MarshallingContext.Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction) A shortcut for defining aFunctionalSwap.<T,S> MarshallingContext.Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction, ThrowingFunction<S, T> unswapFunction) A shortcut for defining aFunctionalSwap.swaps()Returns the bean swaps list.Same asswaps(Object...)but explicitly specifies an array of classes to avoid compilation warnings.Java object swaps.temporalFormat(TemporalFormat value) Temporal wire format.Context configuration property: TimeZone.timeZoneFormat(TimeZoneFormat value) Time-zone wire format.Associates a context class with this builder.An identifying name for this class.typePropertyName(Class<?> on, String value) Bean type property name.typePropertyName(String value) Bean type property name.Disable sorted bean properties.unsortedProperties(boolean value) Same asunsortedProperties()but allows you to explicitly specify the value.unsortedProperties(Class<?>... on) Opt specific bean classes out of alphabetical property sorting.Use Java Introspector.useJavaBeanIntrospector(boolean value) Same asuseJavaBeanIntrospector()but allows you to explicitly specify the value.uuidFormat(UuidFormat value) UUID wire format.Schema validation mode.validateSchema(boolean value) Same asvalidateSchema()but allows you to explicitly specify the value.Methods inherited from class org.apache.juneau.marshall.Context.Builder
annotations, annotations, apply, applyAnnotations, applyAnnotations, asSubtype, build, cache, canApply, copyOrNull, debug, debug, getApplied, getType, impl, isDebug, registerBuilders, self
-
Constructor Details
-
Builder
protected Builder()Constructor. All default settings. -
Builder
Copy constructor.- Parameters:
copyFrom- The bean to copy from.
-
Builder
Copy constructor.- Parameters:
copyFrom- The builder to copy from.
-
-
Method Details
-
beanClassVisibility
Minimum bean class visibility.Classes are not considered beans unless they meet the minimum visibility requirements. For example, if the visibility is
PUBLIC and the bean class isprotected , 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:
// A bean with a protected class and one field. protected class MyBean {public Stringfoo ="bar" ; }// Create a serializer that's capable of serializing the class. WriterSerializerserializer = JsonSerializer .create () .beanClassVisibility(PROTECTED ) .build();// Produces: {"foo","bar"} Stringjson =serializer .write(new MyBean());Notes:
- The
@Marshalledannotation can be used on a non-public bean class to override this setting. - The
@BeanIgnoreannotation can also be used on a public bean class to ignore it as a bean.
See Also:
- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC.
Cannot benull .- Returns:
- This object.
- The
-
beanConstructorVisibility
Minimum bean constructor visibility.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:
// A bean with a protected constructor and one field. public class MyBean {public Stringfoo ;protected MyBean() {} }// Create a parser capable of calling the protected constructor. ReaderParserparser = ReaderParser .create () .beanConstructorVisibility(PROTECTED ) .build();// Use it. MyBeanmyBean =parser .read("{foo:'bar'}" , MyBean.class );Notes:
- The
@BeanCtorannotation can also be used to expose a non-public constructor. - The
@BeanIgnoreannotation can also be used on a public bean constructor to ignore it.
See Also:
- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC.
Cannot benull .- Returns:
- This object.
- The
-
beanDictionary
Returns the bean dictionary list.Gives access to the inner list if you need to make more than simple additions via
beanDictionary(Class...).- Returns:
- The bean dictionary list.
- See Also:
-
beanDictionary
Convenience method forbeanDictionary(ClassInfo...)that acceptsClassobjects.- Parameters:
values- The values to add to this setting.
Cannot containnull values.- Returns:
- This object.
- See Also:
-
beanDictionary
Bean dictionary.The list of classes that make up the bean dictionary in this bean context.
Values are prepended to the list so that later calls can override classes of earlier calls.
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
@Marshalled(typeName)annotation defined on the bean class. For example, if a classFoo has a type-name of"myfoo" , then it would end up serialized as"{_type:'myfoo',...}" in JSON or"<myfoo>...</myfoo>" in XML.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
@Marshalled(typeName). - Any subclass of
BeanDictionaryListcontaining a collection of bean classes with type name annotations. - Any subclass of
BeanDictionaryMapcontaining a mapping of type names to classes without type name annotations. - Any array or collection of the objects above.
Example:
// POJOs with @Marshalled(name) annotations. @Marshalled (typeName="foo" )public class Foo {...}@Marshalled (typeName="bar" )public class Bar {...}// Create a parser and tell it which classes to try to resolve. ReaderParserparser = JsonParser .create () .dictionary(Foo.class , Bar.class ) .addBeanTypes() .build();// A bean with a field with an indeterminate type. public class MyBean {public ObjectmySimpleField ; }// Parse bean. MyBeanmyBean =parser .read("{mySimpleField:{_type:'foo',...}}" , MyBean.class );Another option is to use the
Marshalled.dictionary()annotation on the POJO class itself:// 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. @Marshalled (dictionary={Foo.class ,Bar.class })public class MyBean {public ObjectmySimpleField ;// May contain Foo or Bar object. public Map<String,Object>myMapField ;// May contain Foo or Bar objects. }A typical usage is to allow for HTML documents to be parsed back into HTML beans:
// Use the predefined HTML5 bean dictionary which is a BeanDictionaryList. ReaderParserparser = HtmlParser .create () .dictionary(HtmlBeanDictionary.class ) .build();// Parse an HTML body into HTML beans. Bodybody =parser .read("<body><ul><li>foo</li><li>bar</li></ul>" , Body.class );See Also:
- Parameters:
values- The values to add to this setting.
Cannot containnull values.- Returns:
- This object.
- Any bean class that specifies a value for
-
beanDictionary
Same asbeanDictionary(ClassInfo...)but allows you to pass in a collection of class info objects.- Parameters:
values- The values to add to this setting.
Cannot benull or containnull values.- Returns:
- This object.
- See Also:
-
beanFieldVisibility
Minimum bean field visibility.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:
// A bean with a protected field. public class MyBean {protected Stringfoo ="bar" ; }// Create a serializer that recognizes the protected field. WriterSerializerserializer = JsonSerializer .create () .beanFieldVisibility(PROTECTED ) .build();// Produces: {"foo":"bar"} Stringjson =serializer .write(new MyBean());Bean fields can be ignored as properties entirely by setting the value to
Visibility.NONE// Disable using fields as properties entirely. WriterSerializerserializer = JsonSerializer .create () .beanFieldVisibility(NONE ) .build();Notes:
- The
@BeanPropannotation can also be used to expose a non-public field. - The
@BeanIgnoreannotation can also be used on a public bean field to ignore it as a bean property.
See Also:
- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC.
Cannot benull .- Returns:
- This object.
- The
-
beanInterceptor
public MarshallingContext.Builder beanInterceptor(Class<?> on, Class<? extends BeanInterceptor<?>> value) Bean interceptor.Bean interceptors can be used to intercept calls to getters and setters and alter their values in transit.
Example:
// Interceptor that strips out sensitive information. public class AddressInterceptorextends BeanInterceptor<Address> {public Object readProperty(Addressbean , Stringname , Objectvalue ) {if ("taxInfo" .equals(name ))return "redacted" ;return value ; }public Object writeProperty(Addressbean , Stringname , Objectvalue ) {if ("taxInfo" .equals(name ) &&"redacted" .equals(value ))return TaxInfoUtils.lookup (bean .getStreet(),bean .getCity(),bean .getState());return value ; } }// Our bean class. public class Address {public String getTaxInfo() {...}public void setTaxInfo(Stringvalue ) {...} }// Register filter on serializer or parser. WriterSerializerserializer = JsonSerializer .create () .beanInterceptor(Address.class , AddressInterceptor.class ) .build();// Produces: {"taxInfo":"redacted"} Stringjson =serializer .write(new Address());See Also:
- Parameters:
on- The bean that the filter applies to.
Cannot benull .value- The new value for this setting.
Cannot benull .- Returns:
- This object.
-
beanMapPutReturnsOldValue
BeanMap.put() returns old property value.When enabled, then the
BeanMap.put()method will return old property values. Otherwise, it returnsnull .Disabled by default because it introduces a slight performance penalty during serialization.
Example:
// Create a context that creates BeanMaps with normal put() behavior. MarshallingContextcontext = MarshallingContext .create () .beanMapPutReturnsOldValue() .build(); BeanMap<MyBean>myBeanMap =context .createSession().toBeanMap(new MyBean());myBeanMap .put("foo" ,"bar" ); ObjectoldValue =myBeanMap .put("foo" ,"baz" );// oldValue == "bar" See Also:
- Returns:
- This object.
-
beanMapPutReturnsOldValue
Same asbeanMapPutReturnsOldValue()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
beanMethodVisibility
Minimum bean method visibility.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:
// A bean with a protected getter. public class MyBean {public String getFoo() {return "foo" ; }protected String getBar() {return "bar" ; } }// Create a serializer that looks for protected getters and setters. WriterSerializerserializer = JsonSerializer .create () .beanMethodVisibility(PROTECTED ) .build();// Produces: {"foo":"foo","bar":"bar"} Stringjson =serializer .write(new MyBean());Notes:
- The
@BeanPropannotation can also be used to expose a non-public method. - The
@BeanIgnoreannotation can also be used on a public bean getter/setter to ignore it as a bean property.
See Also:
- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC- Returns:
- This object.
- The
-
beanProperties
Bean property includes.Specifies the set and order of names of properties associated with the bean class.
For example,
beanProperties(MyBean. means only serialize theclass ,"foo,bar" )foo andbar properties on the specified bean. Likewise, parsing will ignore any bean properties not specified and either throw an exception or silently ignore them depending on whetherignoreUnknownBeanProperties()has been called.This value is entirely optional if you simply want to expose all the getters and public fields on a class as bean properties. However, it's useful if you want certain getters to be ignored or you want the properties to be serialized in a particular order. Note that on IBM JREs, the property order is the same as the order in the source code, whereas on Oracle JREs, the order is entirely random.
Setting applies to specified class and all subclasses.
Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ="foo" ,bar ="bar" ,baz ="baz" ; }// Create a serializer that includes only the 'foo' and 'bar' properties on the MyBean class. WriterSerializerserializer = JsonSerializer .create () .beanProperties(MyBean.class ,"foo,bar" ) .build();// Produces: {"foo":"foo","bar":"bar"} Stringjson =serializer .write(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClass ).properties(properties ).build());See Also:
BeanType.properties()/BeanType.p()- On an annotation on the bean class itself.
- Parameters:
beanClass- The bean class.
Cannot benull .properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanProperties
Bean property includes.Specifies the set and order of names of properties associated with bean classes.
For example,
beanProperties(AMap. means only serialize theof ("MyBean" ,"foo,bar" ))foo andbar properties on the specified bean. Likewise, parsing will ignore any bean properties not specified and either throw an exception or silently ignore them depending on whetherignoreUnknownBeanProperties()has been called.This value is entirely optional if you simply want to expose all the getters and public fields on a class as bean properties. However, it's useful if you want certain getters to be ignored or you want the properties to be serialized in a particular order. Note that on IBM JREs, the property order is the same as the order in the source code, whereas on Oracle JREs, the order is entirely random.
Setting applies to specified class and all subclasses.
Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ="foo" ,bar ="bar" ,baz ="baz" ; }// Create a serializer that includes only the 'foo' and 'bar' properties on the MyBean class. WriterSerializerserializer = JsonSerializer .create () .beanProperties(AMap.of ("MyBean" ,"foo,bar" )) .build();// Produces: {"foo":"foo","bar":"bar"} Stringjson =serializer .write(new MyBean());This method is functionally equivalent to the following code for each entry:
builder .annotations(MarshalledAnnotation.create (key ).properties(value .toString()).build());See Also:
BeanType.properties()/BeanType.p()- On an annotation on the bean class itself.
- Parameters:
values- The values to add to this builder.
Keys are bean class names which can be a simple name, fully-qualified name, or"*" for all beans.
Values are comma-delimited lists of property names. Non-String objects are first converted to Strings.
Cannot benull .- Returns:
- This object.
-
beanProperties
Bean property includes.Specifies the set and order of names of properties associated with the bean class.
For example,
beanProperties( means only serialize the"MyBean" ,"foo,bar" )foo andbar properties on the specified bean. Likewise, parsing will ignore any bean properties not specified and either throw an exception or silently ignore them depending on whetherignoreUnknownBeanProperties()has been called.This value is entirely optional if you simply want to expose all the getters and public fields on a class as bean properties. However, it's useful if you want certain getters to be ignored or you want the properties to be serialized in a particular order. Note that on IBM JREs, the property order is the same as the order in the source code, whereas on Oracle JREs, the order is entirely random.
Setting applies to specified class and all subclasses.
Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ="foo" ,bar ="bar" ,baz ="baz" ; }// Create a serializer that includes only the 'foo' and 'bar' properties on the MyBean class. WriterSerializerserializer = JsonSerializer .create () .beanProperties("MyBean" ,"foo,bar" ) .build();// Produces: {"foo":"foo","bar":"bar"} Stringjson =serializer .write(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClassName ).properties(properties ).build());See Also:
BeanType.properties()/BeanType.p()- On an annotation on the bean class itself.
- Parameters:
beanClassName- The bean class name.
Can be a simple name, fully-qualified name, or"*" for all beans.properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesExcludes
Bean property excludes.Specifies to exclude the specified list of properties for the specified bean class.
Same as
beanProperties(Class, String)except you specify a list of bean property names that you want to exclude from serialization.Setting applies to specified class and all subclasses.
Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ="foo" ,bar ="bar" ,baz ="baz" ; }// Create a serializer that excludes the "bar" and "baz" properties on the MyBean class. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesExcludes(MyBean.class ,"bar,baz" ) .build();// Produces: {"foo":"foo"} Stringjson =serializer .write(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClass ).excludeProperties(properties ).build());See Also:
- Parameters:
beanClass- The bean class.
Cannot benull .properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesExcludes
Bean property excludes.Specifies to exclude the specified list of properties for the specified bean classes.
Same as
beanProperties(Map)except you specify a list of bean property names that you want to exclude from serialization.Setting applies to specified class and all subclasses.
Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ="foo" ,bar ="bar" ,baz ="baz" ; }// Create a serializer that excludes the "bar" and "baz" properties on the MyBean class. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesExcludes(AMap.of("MyBean" ,"bar,baz" )) .build();// Produces: {"foo":"foo"} Stringjson =serializer .write(new MyBean());This method is functionally equivalent to the following code for each entry:
builder .annotations(MarshalledAnnotation.create (key ).excludeProperties(value .toString()).build());See Also:
- Parameters:
values- The values to add to this builder.
Keys are bean class names which can be a simple name, fully-qualified name, or"*" for all beans.
Values are comma-delimited lists of property names. Non-String objects are first converted to Strings.
Cannot benull .- Returns:
- This object.
-
beanPropertiesExcludes
Bean property excludes.Specifies to exclude the specified list of properties for the specified bean class.
Same as
beanPropertiesExcludes(String, String)except you specify a list of bean property names that you want to exclude from serialization.Setting applies to specified class and all subclasses.
Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ="foo" ,bar ="bar" ,baz ="baz" ; }// Create a serializer that excludes the "bar" and "baz" properties on the MyBean class. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesExcludes("MyBean" ,"bar,baz" ) .build();// Produces: {"foo":"foo"} Stringjson =serializer .write(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClassName ).excludeProperties(properties ).build());See Also:
- Parameters:
beanClassName- The bean class name.
Can be a simple name, fully-qualified name, or"*" for all bean classes.
Cannot benull .properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesReadOnly
Read-only bean properties.Specifies one or more properties on a bean that are read-only despite having valid getters. Serializers will serialize such properties as usual, but parsers will silently ignore them. Note that this is different from the
beanProperties/beanPropertiesExcludessettings which include or exclude properties for both serializers and parsers.Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ,bar ,baz ; }// Create a serializer with read-only property settings. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesReadOnly(MyBean.class ,"bar,baz" ) .build();// All 3 properties will be serialized. Stringjson =serializer .write(new MyBean());// Create a parser with read-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesReadOnly(MyBean.class ,"bar,baz" ) .ignoreUnknownBeanProperties() .build();// Parser ignores bar and baz properties. MyBeanmyBean =parser .read("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClass ).readOnlyProperties(properties ).build());See Also:
- Parameters:
beanClass- The bean class.
Cannot benull .properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesReadOnly
Read-only bean properties.Specifies one or more properties on beans that are read-only despite having valid getters. Serializers will serialize such properties as usual, but parsers will silently ignore them. Note that this is different from the
beanProperties/beanPropertiesExcludessettings which include or exclude properties for both serializers and parsers.Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ,bar ,baz ; }// Create a serializer with read-only property settings. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesReadOnly(AMap.of ("MyBean" ,"bar,baz" )) .build();// All 3 properties will be serialized. Stringjson =serializer .write(new MyBean());// Create a parser with read-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesReadOnly(AMap.of ("MyBean" ,"bar,baz" )) .ignoreUnknownBeanProperties() .build();// Parser ignores bar and baz properties. MyBeanmyBean =parser .read("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code for each entry:
builder .annotations(MarshalledAnnotation.create (key ).readOnlyProperties(value .toString()).build());See Also:
- Parameters:
values- The values to add to this builder.
Keys are bean class names which can be a simple name, fully-qualified name, or"*" for all beans.
Values are comma-delimited lists of property names. Non-String objects are first converted to Strings.
Cannot benull .- Returns:
- This object.
-
beanPropertiesReadOnly
Read-only bean properties.Specifies one or more properties on a bean that are read-only despite having valid getters. Serializers will serialize such properties as usual, but parsers will silently ignore them. Note that this is different from the
beanProperties/beanPropertiesExcludessettings which include or exclude properties for both serializers and parsers.Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ,bar ,baz ; }// Create a serializer with read-only property settings. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesReadOnly("MyBean" ,"bar,baz" ) .build();// All 3 properties will be serialized. Stringjson =serializer .write(new MyBean());// Create a parser with read-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesReadOnly("MyBean" ,"bar,baz" ) .ignoreUnknownBeanProperties() .build();// Parser ignores bar and baz properties. MyBeanmyBean =parser .read("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClassName ).readOnlyProperties(properties ).build());See Also:
- Parameters:
beanClassName- The bean class name.
Can be a simple name, fully-qualified name, or"*" for all bean classes.properties- Comma-delimited list of property names.- Returns:
- This object.
-
beanPropertiesWriteOnly
Write-only bean properties.Specifies one or more properties on a bean that are write-only despite having valid setters. Parsers will parse such properties as usual, but serializers will silently ignore them. Note that this is different from the
beanProperties/beanPropertiesExcludessettings which include or exclude properties for both serializers and parsers.Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ,bar ,baz ; }// Create a serializer with write-only property settings. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesWriteOnly(MyBean.class ,"bar,baz" ) .build();// Only foo will be serialized. Stringjson =serializer .write(new MyBean());// Create a parser with write-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesWriteOnly(MyBean.class ,"bar,baz" ) .build();// Parser parses all 3 properties. MyBeanmyBean =parser .read("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClass ).writeOnlyProperties(properties ).build());See Also:
- Parameters:
beanClass- The bean class.
Cannot benull .properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesWriteOnly
Write-only bean properties.Specifies one or more properties on a bean that are write-only despite having valid setters. Parsers will parse such properties as usual, but serializers will silently ignore them. Note that this is different from the
beanProperties/beanPropertiesExcludessettings which include or exclude properties for both serializers and parsers.Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ,bar ,baz ; }// Create a serializer with write-only property settings. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesWriteOnly(AMap.of ("MyBean" ,"bar,baz" )) .build();// Only foo will be serialized. Stringjson =serializer .write(new MyBean());// Create a parser with write-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesWriteOnly(AMap.of ("MyBean" ,"bar,baz" )) .build();// Parser parses all 3 properties. MyBeanmyBean =parser .read("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code for each entry:
builder .annotations(MarshalledAnnotation.create (key ).writeOnlyProperties(value .toString()).build());See Also:
- Parameters:
values- The values to add to this builder.
Keys are bean class names which can be a simple name, fully-qualified name, or"*" for all beans.
Values are comma-delimited lists of property names. Non-String objects are first converted to Strings.
Cannot benull .- Returns:
- This object.
-
beanPropertiesWriteOnly
Write-only bean properties.Specifies one or more properties on a bean that are write-only despite having valid setters. Parsers will parse such properties as usual, but serializers will silently ignore them. Note that this is different from the
beanProperties/beanPropertiesExcludessettings which include or exclude properties for both serializers and parsers.Example:
// A bean with 3 properties. public class MyBean {public Stringfoo ,bar ,baz ; }// Create a serializer with write-only property settings. WriterSerializerserializer = JsonSerializer .create () .beanPropertiesWriteOnly("MyBean" ,"bar,baz" ) .build();// Only foo will be serialized. Stringjson =serializer .write(new MyBean());// Create a parser with write-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesWriteOnly("MyBean" ,"bar,baz" ) .build();// Parser parses all 3 properties. MyBeanmyBean =parser .read("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(MarshalledAnnotation.create (beanClassName ).writeOnlyProperties(properties ).build());See Also:
- Parameters:
beanClassName- The bean class name.
Can be a simple name, fully-qualified name, or"*" for all bean classes.properties- Comma-delimited list of property names.- Returns:
- This object.
-
beansRequireDefaultConstructor
Beans require no-arg constructors.When enabled, 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
Object.toString()method.Example:
// A bean without a no-arg constructor. public class MyBean {// A property method. public Stringfoo ="bar" ;// A no-arg constructor public MyBean(Stringfoo ) {this .foo =foo ; }@Override public String toString() {return "bar" ; } }// Create a serializer that ignores beans without default constructors. WriterSerializerserializer = JsonSerializer .create () .beansRequireDefaultConstructor() .build();// Produces: "bar" Stringjson =serializer .write(new MyBean());Notes:
- The
@Marshalledannotation can be used on a bean class to override this setting. - The
@BeanIgnoreannotation can also be used on a class to ignore it as a bean.
See Also:
- Returns:
- This object.
- The
-
beansRequireDefaultConstructor
Same asbeansRequireDefaultConstructor()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
beansRequireSerializable
Beans require Serializable interface.When enabled, a Java class must implement the
Serializableinterface to be considered a bean. Otherwise, the bean will be serialized as a string using theObject.toString()method.Example:
// A bean without a Serializable interface. public class MyBean {// A property method. public Stringfoo ="bar" ;@Override public String toString() {return "bar" ; } }// Create a serializer that ignores beans not implementing Serializable. WriterSerializerserializer = JsonSerializer .create () .beansRequireSerializable() .build();// Produces: "bar" Stringjson =serializer .write(new MyBean());Notes:
- The
@Marshalledannotation can be used on a bean class to override this setting. - The
@BeanIgnoreannotation can also be used on a class to ignore it as a bean.
See Also:
- Returns:
- This object.
- The
-
beansRequireSerializable
Same asbeansRequireSerializable()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
beansRequireSettersForGetters
Beans require setters for getters.When enabled, ignore read-only properties (properties with getters but not setters).
Example:
// A bean without a Serializable interface. public class MyBean {// A read/write property. public String getFoo() {return "foo" ; }public void setFoo(Stringfoo ) { ... }// A read-only property. public String getBar() {return "bar" ; } }// Create a serializer that ignores bean properties without setters. WriterSerializerserializer = JsonSerializer .create () .beansRequireSettersForGetters() .build();// Produces: {"foo":"foo"} Stringjson =serializer .write(new MyBean());Notes:
- The
@BeanPropannotation can be used on the getter to override this setting. - The
@BeanIgnoreannotation can also be used on getters to ignore them as bean properties.
- Returns:
- This object.
- The
-
beansRequireSettersForGetters
Same asbeansRequireSettersForGetters()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
beanStore
Sets the bean store used for factory-based instantiation.The bean store is used to resolve
BeanFactoryinstances registered via@BeanType (factory=X.class) and@BeanProp (factory=X.class) annotations. When a factory class is encountered, the framework first looks it up in the bean store before attempting direct instantiation.Typically set to a
SpringBeanStorewrapping the application'sApplicationContextso that Spring-managed factories are resolved automatically.Example:
public class MyRestServletextends BasicRestServlet {@Autowired ApplicationContextctx ;@Override protected MarshallingContext createBeanContext(MarshallingContext.Builder<?>builder ) {return builder .beanStore(new SpringBeanStore(ctx )).build(); } }- Parameters:
value- The bean store, ornull to use direct instantiation only.- Returns:
- This object.
-
build
Description copied from class:Context.BuilderBuild the object.- Overrides:
buildin classContext.Builder<MarshallingContext.Builder>- Returns:
- The built object.
-
copy
Description copied from class:Context.BuilderCopy creator.- Specified by:
copyin classContext.Builder<MarshallingContext.Builder>- Returns:
- A new mutable copy of this builder.
-
copyOrNull
Null-safe copy: returns a deep copy of the specified value, ornull if the value isnull .- Parameters:
value- The value to copy. Can benull (returnsnull ).- Returns:
- A copy of the value, or
null if the value wasnull .
-
dictionaryOn
Bean dictionary.This is identical to
beanDictionary(Class...), but specifies a dictionary within the context of a single class as opposed to globally.Example:
// POJOs with @Marshalled(name) annotations. @Marshalled (typeName="foo" )public class Foo {...}@Marshalled (typeName="bar" )public class Bar {...}// A bean with a field with an indeterminate type. public class MyBean {public ObjectmySimpleField ; }// Create a parser and tell it which classes to try to resolve. ReaderParserparser = JsonParser .create () .dictionaryOn(MyBean.class , Foo.class , Bar.class ) .build();// Parse bean. MyBeanmyBean =parser .read("{mySimpleField:{_type:'foo',...}}" , MyBean.class );This is functionally equivalent to the
Marshalled.dictionary()annotation.See Also:
- Parameters:
on- The class that the dictionary values apply to.values- The new values for this setting.- Returns:
- This object.
-
disableBeansRequireSomeProperties
Beans don't require at least one property.When enabled, then a Java class doesn't need to contain at least 1 property to be considered a bean. Otherwise, the bean will be serialized as a string using the
Object.toString()method.The
@Marshalledannotation can be used on a class to override this setting whentrue .Example:
// A bean with no properties. public class MyBean { }// Create a serializer that serializes beans even if they have zero properties. WriterSerializerserializer = JsonSerializer .create () .disableBeansRequireSomeProperties() .build();// Produces: {} Stringjson =serializer .write(new MyBean());Notes:
- The
@Marshalledannotation can be used on the class to force it to be recognized as a bean class even if it has no properties.
See Also:
- Returns:
- This object.
- The
-
disableBeansRequireSomeProperties
Same asdisableBeansRequireSomeProperties()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
disableIgnoreMissingSetters
Don't silently ignore missing setters.When enabled, trying to set a value on a bean property without a setter will throw a
BeanRuntimeException. Otherwise, it will be silently ignored.Example:
// A bean with a property with a getter but not a setter. public class MyBean {public void getFoo() {return "foo" ; } }// Create a parser that throws an exception if a setter is not found but a getter is. ReaderParserparser = JsonParser .create () .disableIgnoreMissingSetters() .build();// Throws a ParseException. MyBeanmyBean =parser .read("{foo:'bar'}" , MyBean.class );Notes:
- The
@BeanIgnoreannotation can also be used on getters and fields to ignore them.
See Also:
- Returns:
- This object.
- The
-
disableIgnoreMissingSetters
Same asdisableIgnoreMissingSetters()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
disableIgnoreTransientFields
Don't ignore transient fields.When enabled, methods and fields marked as
transient will not be ignored as bean properties.Example:
// A bean with a transient field. public class MyBean {public transient Stringfoo ="foo" ; }// Create a serializer that doesn't ignore transient fields. WriterSerializerserializer = JsonSerializer .create () .disableIgnoreTransientFields() .build();// Produces: {"foo":"foo"} Stringjson =serializer .write(new MyBean());Notes:
- The
@BeanPropannotation can also be used on transient fields to keep them from being ignored.
See Also:
- Returns:
- This object.
- The
-
disableIgnoreTransientFields
Same asdisableIgnoreTransientFields()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
disableIgnoreUnknownNullBeanProperties
Don't ignore unknown properties with null values.When enabled, trying to set a
null value on a non-existent bean property will throw aBeanRuntimeException. Otherwise it will be silently ignored.Example:
// A bean with a single property. public class MyBean {public Stringfoo ; }// Create a parser that throws an exception on an unknown property even if the value being set is null. ReaderParserparser = JsonParser .create () .disableIgnoreUnknownNullBeanProperties() .build();// Throws a BeanRuntimeException wrapped in a ParseException on the unknown 'bar' property. MyBeanmyBean =parser .read("{foo:'foo',bar:null}" , MyBean.class );See Also:
- Returns:
- This object.
-
disableIgnoreUnknownNullBeanProperties
Same asdisableIgnoreUnknownNullBeanProperties()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
disableInterfaceProxies
Don't use interface proxies.When enabled, interfaces will be instantiated as proxy classes through the use of an
InvocationHandlerif there is no other way of instantiating them. Otherwise, throws aBeanRuntimeException.See Also:
- Returns:
- This object.
-
disableInterfaceProxies
Same asdisableInterfaceProxies()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
example
POJO example.Specifies an example in JSON 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. WriterSerializerserializer = JsonSerializer .create () .example(MyBean.class ,"{foo:'bar'}" ) .build();This is a shorthand method for the following code:
builder .annotations(MarshalledAnnotation.create (pojoClass ).example(json ).build())POJO examples can also be defined on classes via the following:
- A static field annotated with
@Example. - A static method annotated with
@Examplewith zero arguments or oneMarshallingSessionargument. - A static method with name
example with no arguments or oneMarshallingSessionargument.
See Also:
- Type Parameters:
T- The POJO class type.- Parameters:
pojoClass- The POJO class.
Cannot benull .json- The JSON 5 representation of the example.
Can benull or empty (treated as no example).- Returns:
- This object.
- A static field annotated with
-
example
POJO example.Specifies an example of the specified class.
Examples are used in cases such as POJO examples in Swagger documents.
Example:
// Create a serializer that excludes the 'foo' and 'bar' properties on the MyBean class. WriterSerializerserializer = JsonSerializer .create () .example(MyBean.class ,new MyBean().setFoo("foo" ).setBar(123)) .build();This is a shorthand method for the following code:
builder .annotations(MarshalledAnnotation.create (pojoClass ).example(Json5.DEFAULT .toString(object )).build())Notes:
- Using this method assumes the serialized form of the object is the same as that produced by the default serializer. This may not be true based on settings or swaps on the constructed serializer.
POJO examples can also be defined on classes via the following:
- The
Marshalled.example()annotation on the class itself. - A static field annotated with
@Example. - A static method annotated with
@Examplewith zero arguments or oneMarshallingSessionargument. - A static method with name
example with no arguments or oneMarshallingSessionargument.
- Type Parameters:
T- The POJO class.- Parameters:
pojoClass- The POJO class.
Cannot benull .o- An instance of the POJO class used for examples.
Can benull (will be serialized as"null" ).- Returns:
- This object.
-
findFluentSetters
Find fluent setters.When enabled, fluent setters are detected on beans during parsing.
Fluent setters must have the following attributes:
- Public.
- Not static.
- Take in one parameter.
- Return the bean itself.
Example:
// A bean with a fluent setter. public class MyBean {public MyBean foo(Stringvalue ) {...} }// Create a parser that finds fluent setters. ReaderParserparser = JsonParser .create () .findFluentSetters() .build();// Parse into bean using fluent setter. MyBeanmyBean =parser .read("{foo:'bar'}" );Notes:
- The
@BeanPropannotation can also be used on methods to individually identify them as fluent setters. - The
@BeanType.findFluentSetters()annotation can also be used on classes to specify to look for fluent setters.
See Also:
- Returns:
- This object.
-
findFluentSetters
Same asfindFluentSetters()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
findFluentSetters
Find fluent setters.Identical to
findFluentSetters()but enables it on a specific class only.Example:
// A bean with a fluent setter. public class MyBean {public MyBean foo(Stringvalue ) {...} }// Create a parser that finds fluent setters. ReaderParserparser = JsonParser .create () .findFluentSetters(MyBean.class ) .build();// Parse into bean using fluent setter. MyBeanmyBean =parser .read("{foo:'bar'}" );Notes:
- This method is functionally equivalent to using the
BeanType.findFluentSetters()annotation.
See Also:
- Parameters:
on- The class that this applies to.
Cannot benull .- Returns:
- This object.
- This method is functionally equivalent to using the
-
hashKey
Description copied from class:Context.BuilderReturns the hashkey of this builder.Used to return previously instantiated context beans that have matching hashkeys. The
HashKeyobject is suitable for use as a hashmap key of a map of context beans. A context bean is considered equivalent if theHashKey.equals(Object)method is the same.- Overrides:
hashKeyin classContext.Builder<MarshallingContext.Builder>- Returns:
- The hashkey of this builder.
-
activeView
Sets the default active view name for all sessions created from this context.When set, only bean properties whose declared
MarshalledProp.view()set contains this view name will be included during serialization. On the parse side, properties outside the active view are routed through the existing unknown/ignored-property mechanism governed byignoreUnknownBeanProperties().Untagged properties (those whose declared view set is empty) follow the default-view-inclusion policy: included under every active view unless
disableDefaultViewInclusion()has been called.This value can be overridden per serialization or parse call via the session builder (e.g.
MarshallingSession.Builder.activeView(String)).Example:
JsonSerializer
serializer = JsonSerializer.create () .activeView("summary" ) .build();See Also:
- Parameters:
value- The active view name. Usenull to disable view filtering.- Returns:
- This object.
- Since:
- 10.0.0
-
disableDefaultViewInclusion
Disables the default-view-inclusion policy.By default, bean properties that carry no
MarshalledProp.view()declaration are included under every active view (matching Jackson'sDEFAULT_VIEW_INCLUSIONbehavior). Calling this method reverses the policy: untagged properties are excluded when any active view is set.See Also:
- Returns:
- This object.
- Since:
- 10.0.0
-
disableDefaultViewInclusion
Same asdisableDefaultViewInclusion()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
- Since:
- 10.0.0
-
ignoreInvocationExceptionsOnGetters
Ignore invocation errors on getters.When enabled, errors thrown when calling bean getter methods will silently be ignored. Otherwise, a
BeanRuntimeExceptionis thrown.Example:
// A bean with a property that throws an exception. public class MyBean {public String getFoo() {throw new RuntimeException("foo" ); } }// Create a serializer that ignores bean getter exceptions. WriterSerializerserializer = JsonSerializer .create () .ingoreInvocationExceptionsOnGetters() .build();// Exception is ignored. Stringjson =serializer .write(new MyBean());See Also:
- Returns:
- This object.
-
ignoreInvocationExceptionsOnGetters
Same asignoreInvocationExceptionsOnGetters()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
ignoreInvocationExceptionsOnSetters
Ignore invocation errors on setters.When enabled, errors thrown when calling bean setter methods will silently be ignored. Otherwise, a
BeanRuntimeExceptionis thrown.Example:
// A bean with a property that throws an exception. public class MyBean {public void setFoo(Stringfoo ) {throw new RuntimeException("foo" ); } }// Create a parser that ignores bean setter exceptions. ReaderParserparser = JsonParser .create () .ignoreInvocationExceptionsOnSetters() .build();// Exception is ignored. MyBeanmyBean =parser .read("{foo:'bar'}" , MyBean.class );See Also:
- Returns:
- This object.
-
ignoreInvocationExceptionsOnSetters
Same asignoreInvocationExceptionsOnSetters()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
ignoreUnknownBeanProperties
Ignore unknown properties.When enabled, trying to set a value on a non-existent bean property will silently be ignored. Otherwise, a
BeanRuntimeExceptionis thrown.Example:
// A bean with a single property. public class MyBean {public Stringfoo ; }// Create a parser that ignores missing bean properties. ReaderParserparser = JsonParser .create () .ignoreUnknownBeanProperties() .build();// Doesn't throw an exception on unknown 'bar' property. MyBeanmyBean =parser .read("{foo:'foo',bar:'bar'}" , MyBean.class );See Also:
- Returns:
- This object.
-
ignoreUnknownBeanProperties
Same asignoreUnknownBeanProperties()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
validateSchema
Schema validation mode.When enabled, bean property values are validated against the constraints declared by
@Schemaannotations on those properties. Validation runs during both parsing (value set on the bean) and serialization (value read from the bean).Backed by the typed
JsonSchemabean injuneau-bean-jsonschemaand JSON Schema Draft 2020-12 semantics. Validation failures throwSchemaValidationExceptionwrapped inBeanRuntimeException; the parser surfaces them asParseExceptionand the serializer surfaces them asSerializeException.If
juneau-bean-jsonschemais not on the classpath, this flag becomes a silent no-op.Example:
// A bean with a length-constrained property. public class MyBean {@Schema (minLength="2" , maxLength="10" )public Stringname ; }// Parser that validates inbound values. ReaderParserp = JsonParser.create ().validateSchema().build();p .read("{name:'a'}" , MyBean.class );// throws ParseException - too short See Also:
- Returns:
- This object.
- Since:
- 10.0.0
-
validateSchema
Same asvalidateSchema()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
- Since:
- 10.0.0
-
ignoreUnknownEnumValues
Ignore unknown properties.When enabled, unknown enum values will be set to
null instead of throwing an exception.See Also:
- Returns:
- This object.
-
ignoreUnknownEnumValues
Same asignoreUnknownEnumValues()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
implClass
Implementation classes.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:
// A bean interface. public interface MyBean { ... }// A bean implementation. public class MyBeanImplimplements MyBean { ... }// Create a parser that instantiates MyBeanImpls when parsing MyBeans. ReaderParserparser = JsonParser .create () .implClass(MyBean.class , MyBeanImpl.class ) .build();// Instantiates a MyBeanImpl, MyBeanmyBean =parser .read("..." , MyBean.class );- Parameters:
interfaceClass- The interface class.
Cannot benull .implClass- The implementation class.
Cannot benull .- Returns:
- This object.
-
implClasses
Implementation classes.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:
// A bean with a single property. public interface MyBean { ... }// A bean with a single property. public class MyBeanImplimplements MyBean { ... }// Create a parser that instantiates MyBeanImpls when parsing MyBeans. ReaderParserparser = JsonParser .create () .implClasses(AMap.of (MyBean.class , MyBeanImpl.class )) .build();// Instantiates a MyBeanImpl, MyBeanmyBean =parser .read("..." , MyBean.class );- Parameters:
values- The new value for this setting.
Cannot benull .- Returns:
- This object.
-
interfaceClass
Identifies a class to be used as the interface class for the specified class and all subclasses.When specified, only the list of properties defined on the interface class will be used during serialization. Additional properties on subclasses will be ignored.
// Parent class or interface public abstract class A {public Stringfoo ="foo" ; }// Sub class public class A1extends A {public Stringbar ="bar" ; }// Create a serializer and define our interface class mapping. WriterSerializerserializer = JsonSerializer .create () .interfaceClass(A1.class , A.class ) .build();// Produces "{"foo":"foo"}" Stringjson =serializer .write(new A1());This annotation can be used on the parent class so that it filters to all child classes, or can be set individually on the child classes.
Notes:
- The
@BeanType(interfaceClass)annotation is the equivalent annotation-based solution.
- Parameters:
on- The class that the interface class applies to.
Cannot benull .value- The new value for this setting.
Cannot benull .- Returns:
- This object.
- The
-
interfaces
Identifies a set of interfaces.When specified, only the list of properties defined on the interface class will be used during serialization of implementation classes. Additional properties on subclasses will be ignored.
// Parent class or interface public abstract class A {public Stringfoo ="foo" ; }// Sub class public class A1extends A {public Stringbar ="bar" ; }// Create a serializer and define our interface class mapping. WriterSerializerserializer = JsonSerializer .create () .interfaces(A.class ) .build();// Produces "{"foo":"foo"}" Stringjson =serializer .write(new A1());This annotation can be used on the parent class so that it filters to all child classes, or can be set individually on the child classes.
Notes:
- The
@BeanType(interfaceClass)annotation is the equivalent annotation-based solution.
- Parameters:
value- The new value for this setting.
Cannot benull .- Returns:
- This object.
- The
-
locale
Context configuration property: Locale.Specifies the default locale for serializer and parser sessions when not specified via
MarshallingSession.Builder.locale(Locale). Typically used for POJO swaps that need to deal with locales such as swaps that convertDate andCalendar objects to strings by accessing it via the session passed into theObjectSwap.swap(MarshallingSession, Object)andObjectSwap.unswap(MarshallingSession, Object, ClassMeta, String)methods.Example:
// Define a POJO swap that skips serializing beans if we're in the UK. public class MyBeanSwapextends StringSwap<MyBean> {@Override public String swap(MarshallingSessionsession , MyBeanbean )throws Exception {if (session .getLocale().equals(Locale.UK ))return null ;return bean .toString(); } }// Create a serializer that uses the specified locale if it's not passed in through session args. WriterSerializerserializer = JsonSerializer .create () .locale(Locale.UK ) .swaps(MyBeanSwap.class ) .build();See Also:
- Parameters:
value- The new value for this property.
Cannot benull .- Returns:
- This object.
-
mediaType
Context configuration property: Media type.Specifies the default media type for serializer and parser sessions when not specified via
MarshallingSession.Builder.mediaType(MediaType). Typically used for POJO swaps that need to serialize the same POJO classes differently depending on the specific requested media type. For example, a swap could handle a request for media types"application/json" and"application/json+foo" slightly differently even though they're both being handled by the same JSON serializer or parser.Example:
// Define a POJO swap that skips serializing beans if the media type is application/json. public class MyBeanSwapextends StringSwap<MyBean> {@Override public String swap(MarshallingSessionsession , MyBeanbean )throws Exception {if (session .getMediaType().equals("application/json" ))return null ;return bean .toString(); } }// Create a serializer that uses the specified media type if it's not passed in through session args. WriterSerializerserializer = JsonSerializer .create () .mediaType(MediaType.JSON ) .build();See Also:
- Parameters:
value- The new value for this property.
Can benull (no default media type will be set).- Returns:
- This object.
-
notBeanClasses
Returns the set of not-bean classes.Gives access to the inner set if you need to make more than simple additions via
notBeanClasses(ClassInfo...).- Returns:
- The set of not-bean classes.
- See Also:
-
notBeanClasses
Convenience method fornotBeanClasses(ClassInfo...)that acceptsClassobjects.- Parameters:
values- The values to add to this setting.
Cannot containnull values.- Returns:
- This object.
- See Also:
-
notBeanClasses
Bean class exclusions.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:
// A bean with a single property. public class MyBean {public Stringfoo ="bar" ;public String toString() {return "baz" ; } }// Create a serializer that doesn't treat MyBean as a bean class. WriterSerializerserializer = JsonSerializer .create () .notBeanClasses(MyBean.class ) .build();// Produces "baz" instead of {"foo":"bar"} Stringjson =serializer .write(new MyBean());Notes:
- The
@BeanIgnoreannotation can also be used on classes to prevent them from being recognized as beans.
See Also:
- Parameters:
values- The values to add to this setting.
Cannot containnull values.- Returns:
- This object.
-
notBeanClasses
Same asnotBeanClasses(ClassInfo...)but allows you to pass in a collection of class info objects.- Parameters:
values- The values to add to this setting.
Cannot benull or containnull values.- Returns:
- This object.
- See Also:
-
notBeanPackages
Returns the list of not-bean Java package names.Gives access to the inner list if you need to make more than simple additions via
notBeanPackages(String...).- Returns:
- The list of not-bean Java package names.
- See Also:
-
notBeanPackages
Same asnotBeanPackages(String...)but allows you to pass in a collection of classes.- Parameters:
values- The values to add to this setting.
Cannot benull or containnull values.- Returns:
- This object.
- See Also:
-
notBeanPackages
Bean package exclusions.Used as a convenient way of defining the
notBeanClasses(Class...)property for entire packages. Any classes within these packages will be serialized to strings usingObject.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. WriterSerializerserializer = JsonSerializer .create () .notBeanPackages("org.apache.foo" ,"org.apache.bar.*" ) .build();- Parameters:
values- The values to add to this setting.
Values can consist of any of the following types:Packageobjects.- Strings.
- Arrays and collections of anything in this list.
Cannot containnull values.- Returns:
- This object.
-
propertyNamer
Bean property namerSame as
propertyNamer(Class)but allows you to specify a namer for a specific class.Example:
// A bean with a single property. public class MyBean {public StringfooBarBaz ="fooBarBaz" ; }// Create a serializer that uses Dashed-Lower-Case property names for the MyBean class only. // (e.g. "foo-bar-baz" instead of "fooBarBaz") WriterSerializerserializer = JsonSerializer .create () .propertyNamer(MyBean.class , PropertyNamerDLC.class ) .build();// Produces: {"foo-bar-baz":"fooBarBaz"} Stringjson =serializer .write(new MyBean());See Also:
- Parameters:
on- The class that the namer applies to.
Cannot benull .value- The new value for this setting.
The default isBasicPropertyNamer.
Cannot benull .- Returns:
- This object.
-
propertyNamer
Bean property namerThe class to use for calculating bean property names.
Predefined classes:
BasicPropertyNamer- Default.PropertyNamerDLC- Dashed-lower-case names.PropertyNamerULC- Dashed-upper-case names.
Example:
// A bean with a single property. public class MyBean {public StringfooBarBaz ="fooBarBaz" ; }// Create a serializer that uses Dashed-Lower-Case property names. // (e.g. "foo-bar-baz" instead of "fooBarBaz") WriterSerializerserializer = JsonSerializer .create () .propertyNamer(PropertyNamerDLC.class ) .build();// Produces: {"foo-bar-baz":"fooBarBaz"} Stringjson =serializer .write(new MyBean());- Parameters:
value- The new value for this setting.
Can benull (will useBasicPropertyNameras the default).- Returns:
- This object.
-
unsortedProperties
Disable sorted bean properties.By default, all bean properties are serialized and accessed in alphabetical order. Calling this method opts out of that behavior so that declaration order is used instead: record component order for records, field declaration order (superclass first) for other classes, then method-only properties alphabetically.
Example:
// A bean with 3 properties. public class MyBean {public Stringc ="1" ;public Stringb ="2" ;public Stringa ="3" ; }// Create a serializer that does NOT sort bean properties. WriterSerializerserializer = JsonSerializer .create () .unsortedProperties() .build();// Produces: {"c":"1","b":"2","a":"3"} (declaration order) Stringjson =serializer .write(new MyBean());Notes:
- The
@BeanType.unsorted()annotation can also be used to opt out of sorting on a single class.
- Returns:
- This object.
- The
-
unsortedProperties
Same asunsortedProperties()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
recordComponentOrder
Use record component order forRecordbeans.By default, record properties are sorted alphabetically like every other bean. Calling this method makes records keep their component (declaration) order, even when other beans are sorted. Non-record beans are unaffected.
Example:
public record Person(Stringname ,int age ) {} WriterSerializerserializer = JsonSerializer .create () .recordComponentOrder() .build();// Produces: {"name":"Alice","age":30} Stringjson =serializer .write(new Person("Alice" , 30));See Also:
unsortedProperties()(declaration order for every bean, records included)BeanConfig.recordComponentOrder()
- Returns:
- This object.
-
recordComponentOrder
Same asrecordComponentOrder()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-
unsortedProperties
Opt specific bean classes out of alphabetical property sorting.Applies the
@BeanType(unsorted=true)annotation to the specified classes, overriding the default sorted behavior for those specific beans.See Also:
- Parameters:
on- The bean classes to opt out of sorted properties.
Cannot containnull values.- Returns:
- This object.
-
stopClass
Identifies a stop class for the annotated class.Identical in purpose to the stop class specified by
Introspector.getBeanInfo(Class, Class). Any properties in the stop class or in its base classes will be ignored during analysis.For example, in the following class hierarchy, instances of
C3 will include propertyp3 , but notp1 orp2 .Example:
public class C1 {public int getP1(); }public class C2extends C1 {public int getP2(); }public class C3extends C2 {public int getP3(); }// Create a serializer specifies a stop class for C3. WriterSerializerserializer = JsonSerializer .create () .stopClass(C3.class , C2.class ) .build();// Produces: {"p3":"..."} Stringjson =serializer .write(new C3());- Parameters:
on- The class on which the stop class is being applied.
Cannot benull .value- The new value for this setting.
Cannot benull .- Returns:
- This object.
-
swap
public <T,S> MarshallingContext.Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction) A shortcut for defining aFunctionalSwap.Example:
// Create a serializer that performs a custom format for DAte objects. WriterSerializerserializer = JsonSerializer .create () .swap(Date.class , String.class ,x ->format (x )) .build();- Type Parameters:
T- The object type being swapped out.S- The object type being swapped in.- Parameters:
normalClass- The object type being swapped out.
Cannot benull .swappedClass- The object type being swapped in.
Cannot benull .swapFunction- The function to convert the object.
Cannot benull .- Returns:
- This object.
-
swap
public <T,S> MarshallingContext.Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction, ThrowingFunction<S, T> unswapFunction) A shortcut for defining aFunctionalSwap.Example:
// Create a serializer that performs a custom format for Date objects. WriterSerializerserializer = JsonSerializer .create () .swap(Date.class , String.class ,x ->format (x ),x ->parse (x )) .build();- Type Parameters:
T- The object type being swapped out.S- The object type being swapped in.- Parameters:
normalClass- The object type being swapped out.
Cannot benull .swappedClass- The object type being swapped in.
Cannot benull .swapFunction- The function to convert the object during serialization.
Cannot benull .unswapFunction- The function to convert the object during parsing.
Cannot benull .- Returns:
- This object.
-
swaps
Returns the bean swaps list.Gives access to the inner list if you need to make more than simple additions via
swaps(Class...).- Returns:
- The bean swaps list.
- See Also:
-
swaps
Same asswaps(Object...)but explicitly specifies an array of classes to avoid compilation warnings.- Parameters:
values- The values to add to this setting.
Values can consist of any of the following types:- Any subclass of
ObjectSwap. - Any surrogate class. A shortcut for defining a
SurrogateSwap.
Cannot benull .- Any subclass of
- Returns:
- This object.
-
swaps
Java object swaps.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 swap would be a
Calendar object that gets swapped out for an ISO8601 string.Multiple swaps can be associated with a single class. When multiple swaps are applicable to the same class, the media type pattern defined by
ObjectSwap.forMediaTypes()or@Swap(mediaTypes)are used to come up with the best match.Values can consist of any of the following types:
- Any subclass of
ObjectSwap. - Any instance of
ObjectSwap. - Any surrogate class. A shortcut for defining a
SurrogateSwap. - Any array or collection of the objects above.
Example:
// Sample swap for converting Dates to ISO8601 strings. public class MyDateSwapextends StringSwap<Date> {// ISO8601 formatter. private DateFormatformat =new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ" );@Override public String swap(MarshallingSessionsession , Datedate ) {return format .format(date ); }@Override public Date unswap(MarshallingSessionsession , Stringstring , ClassMetahint )throws Exception {return format .parse(string ); } }// Sample bean with a Date field. public class MyBean {public Datedate =new Date(112, 2, 3, 4, 5, 6); }// Create a serializer that uses our date swap. WriterSerializerserializer = JsonSerializer .create () .swaps(MyDateSwap.class ) .build();// Produces: {"date":"2012-03-03T04:05:06-0500"} Stringjson =serializer .write(new MyBean());// Create a serializer that uses our date swap. ReaderParserparser = JsonParser .create () .swaps(MyDateSwap.class ) .build();// Use our parser to parse a bean. MyBeanbean =parser .read(json , MyBean.class );Notes:
- Parameters:
values- The values to add to this setting.
Values can consist of any of the following types:- Any subclass of
ObjectSwap. - Any surrogate class. A shortcut for defining a
SurrogateSwap. - Any array/collection/stream of the objects above.
Cannot benull .- Any subclass of
- Returns:
- This object.
- Any subclass of
-
timeZone
Context configuration property: TimeZone.Specifies the default time zone for serializer and parser sessions when not specified via
MarshallingSession.Builder.timeZone(TimeZone). Typically used for POJO swaps that need to deal with timezones such as swaps that convertDate andCalendar objects to strings by accessing it via the session passed into theObjectSwap.swap(MarshallingSession, Object)andObjectSwap.unswap(MarshallingSession, Object, ClassMeta, String)methods.Example:
// Define a POJO swap that skips serializing beans if the time zone is GMT. public class MyBeanSwapextends StringSwap<MyBean> {@Override public String swap(MarshallingSessionsession , MyBeanbean )throws Exception {if (session .getTimeZone().equals(TimeZone.GMT ))return null ;return bean .toString(); } }// Create a serializer that uses GMT if the timezone is not specified in the session args. WriterSerializerserializer = JsonSerializer .create () .timeZone(TimeZone.GMT ) .build();See Also:
- Parameters:
value- The new value for this property.
Can benull (timezone will not be set, defaults to system timezone).- Returns:
- This object.
-
durationFormat
Duration wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toDurationFormat.ISO_8601_WITH_DAYS).- Returns:
- This object.
-
periodFormat
Period wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toPeriodFormat.ISO_8601).- Returns:
- This object.
-
calendarFormat
Calendar wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toCalendarFormat.ISO_OFFSET_DATE_TIME).- Returns:
- This object.
-
dateFormat
Date wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toDateFormat.ISO_LOCAL_DATE_TIME).- Returns:
- This object.
-
temporalFormat
Temporal wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toTemporalFormat.DEFAULT).- Returns:
- This object.
-
timeZoneFormat
Time-zone wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toTimeZoneFormat.ID).- Returns:
- This object.
-
localeFormat
Locale wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toLocaleFormat.BCP_47).- Returns:
- This object.
-
binaryFormat
Binary wire format.Controls how
values are written to and read from text-based serializer / parser wire formats, and the encoding used by stream-based serializers when converting their byte output to a string.byte []- Parameters:
value- The value for this setting.
Can benull (defaults toBinaryFormat.NOT_SET).- Returns:
- This object.
-
enumFormat
Enum wire format.- Parameters:
value- The value for this setting.
Can benull (defaults toEnumFormat.TO_STRING).- Returns:
- This object.
-
uuidFormat
UUID wire format.Controls how
UUIDvalues are written to text-based wire formats. Binary serializers (BSON / CBOR / MsgPack / Prototext) emit native 16-byte binary regardless of this setting.- Parameters:
value- The value for this setting.
Can benull (defaults toUuidFormat.STANDARD).- Returns:
- This object.
-
bitSetFormat
BitSet wire format.Controls how
BitSetvalues are written to text-based wire formats.- Parameters:
value- The value for this setting.
Can benull (defaults toBitSetFormat.INDICES).- Returns:
- This object.
-
bigNumberFormat
Big-number wire format.Controls how
BigIntegerandBigDecimalvalues are written to text-based wire formats. Useful for safe JS interop where values outside±(2^53 − 1)would silently lose precision.- Parameters:
value- The value for this setting.
Can benull (defaults toBigNumberFormat.NUMBER).- Returns:
- This object.
-
booleanFormat
Boolean wire format.Controls how
Boolean/values are written to text-based wire formats. Binary serializers (BSON / CBOR / MsgPack / Prototext / Parquet) emit a native boolean wire type regardless of this setting.boolean - Parameters:
value- The value for this setting.
Can benull (defaults toBooleanFormat.TRUE_FALSE).- Returns:
- This object.
-
floatFormat
Float / Double non-finite wire format.Controls how non-finite
Float/Doublevalues (NaN/±Infinity) are written to text-based wire formats. The defaultFloatFormat.NaN_AS_NULLis JSON-spec-compliant. Binary serializers emit native IEEE-754 floats regardless of this setting.- Parameters:
value- The value for this setting.
Can benull (defaults toFloatFormat.NaN_AS_NULL).- Returns:
- This object.
-
currencyFormat
Currency wire format.Controls how
Currencyvalues are written to text-based wire formats. The defaultCurrencyFormat.ISO_CODEis the only setting safe for machine-to-machine wires;CurrencyFormat.SYMBOLandCurrencyFormat.DISPLAY_NAMEare locale-sensitive and best-effort on the parse side.- Parameters:
value- The value for this setting.
Can benull (defaults toCurrencyFormat.ISO_CODE).- Returns:
- This object.
-
classFormat
Class wire format.Controls how
Classvalues are written to text-based wire formats. The defaultClassFormat.FQCNmatches the historicalClassSwapbehavior.ClassFormat.SIMPLE_NAMEis serialize-only — the parser path throwsUnsupportedOperationException.- Parameters:
value- The value for this setting.
Can benull (defaults toClassFormat.FQCN).- Returns:
- This object.
-
classLoader
Session classloader.Sets the classloader used when parsing wire-format class names (e.g. FQCN or binary-name strings written by
ClassFormatSwap). Whennull , the thread-context classloader is used as a fallback — which is the historical behavior.Useful in OSGi bundles, webapp classloaders, and plugin systems where the thread-context classloader does not have visibility into the classes that the session needs to resolve.
- Parameters:
value- The classloader to use for class resolution. Can benull to reset to thread-context fallback.- Returns:
- This object.
-
type
Description copied from class:Context.BuilderAssociates a context class with this builder.This is the type of object that this builder creates when the
Context.Builder.build()method is called.By default, it's the outer class of where the builder class is defined.
If
null is set,Context.Builder.build()will throw an exception. The default constructor automatically sets this to the outer class, sonull should only be set explicitly if you want to override the default.- Overrides:
typein classContext.Builder<MarshallingContext.Builder>- Parameters:
value- The context class that this builder should create.
Can benull (will causeContext.Builder.build()to throw an exception).- Returns:
- This object.
-
typeName
An identifying name for this class.The name is used to identify the class type during parsing when it cannot be inferred through reflection. For example, if a bean property is of type
Object , then the serializer will add the name to the output so that the class can be determined during parsing.It is also used to specify element names in XML.
Example:
// Use _type='mybean' to identify this bean. public class MyBean {...}// Create a serializer and specify the type name.. WriterSerializerserializer = JsonSerializer .create () .typeName(MyBean.class ,"mybean" ) .build();// Produces: {"_type":"mybean",...} Stringjson =serializer .write(new MyBean());Notes:
- Equivalent to the
@Marshalled(typeName)annotation.
See Also:
- Parameters:
on- The class the type name is being defined on.
Cannot benull .value- The new value for this setting.
Cannot benull .- Returns:
- This object.
- Equivalent to the
-
typePropertyName
Bean type property name.Same as
typePropertyName(String)except targets a specific bean class instead of globally.Example:
// POJOs with @Marshalled(name) annotations. @Marshalled (typeName="foo" )public class Foo {...}@Marshalled (typeName="bar" )public class Bar {...}// A bean with a field with an indeterminate type. public class MyBean {public ObjectmySimpleField ; }// Create a serializer that uses 't' instead of '_type' for dictionary names. WriterSerializerserializer = JsonSerializer .create () .typePropertyName(MyBean.class ,"t" ) .dictionary(Foo.class , Bar.class ) .build();// Produces "{mySimpleField:{t:'foo',...}}". Stringjson =serializer .write(new MyBean());See Also:
- Parameters:
on- The class the type property name applies to.
Cannot benull .value- The new value for this setting.
The default is"_type" .
Cannot benull .- Returns:
- This object.
-
typePropertyName
Bean type property name.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:
// POJOs with @Marshalled(name) annotations. @Marshalled (typeName="foo" )public class Foo {...}@Marshalled (typeName="bar" )public class Bar {...}// Create a serializer that uses 't' instead of '_type' for dictionary names. WriterSerializerserializer = JsonSerializer .create () .typePropertyName("t" ) .dictionary(Foo.class , Bar.class ) .build();// Create a serializer that uses 't' instead of '_type' for dictionary names. ReaderParserparser = JsonParser .create () .typePropertyName("t" ) .dictionary(Foo.class , Bar.class ) .build();// A bean with a field with an indeterminate type. public class MyBean {public ObjectmySimpleField ; }// Produces "{mySimpleField:{t:'foo',...}}". Stringjson =serializer .write(new MyBean());// Parse bean. MyBeanbean =parser .read(json , MyBean.class );See Also:
- Parameters:
value- The new value for this setting.
The default is"_type" .
Cannot benull .- Returns:
- This object.
-
useJavaBeanIntrospector
Use Java Introspector.Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters.
Most@Marshalledannotations will be ignored.Example:
// Create a serializer that only uses the built-in java bean introspector for finding properties. WriterSerializerserializer = JsonSerializer .create () .useJavaBeanIntrospector() .build();- Returns:
- This object.
-
useJavaBeanIntrospector
Same asuseJavaBeanIntrospector()but allows you to explicitly specify the value.- Parameters:
value- The value for this setting.- Returns:
- This object.
-