Class HtmlSchemaDocSerializer.Builder
- Enclosing class:
- HtmlSchemaDocSerializer
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor, default settings.protectedBuilder(HtmlSchemaDocSerializer copyFrom) Copy constructor.protectedBuilder(HtmlSchemaDocSerializer.Builder copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionSpecifies the accept media types that the serializer can handle.Add"_type" properties when needed.addBeanTypes(boolean value) Same asSerializer.Builder.addBeanTypes()but allows you to explicitly specify the value.Add"_type" properties when needed.addBeanTypesHtml(boolean value) Same asHtmlSerializer.Builder.addBeanTypesHtml()but allows you to explicitly specify the value.Add"_type" properties when needed.addBeanTypesXml(boolean value) Same asXmlSerializer.Builder.addBeanTypesXml()but allows you to explicitly specify the value.addDescriptionsTo(TypeCategory... values) HtmlSchemaSerializer configuration property: Add descriptions.addExamplesTo(TypeCategory... values) HtmlSchemaSerializer configuration property: Add examples.HtmlSerializer configuration property: Add key/value headers on bean/map tables.addKeyValueTableHeaders(boolean value) Same asHtmlSerializer.Builder.addKeyValueTableHeaders()but allows you to explicitly specify the value.Add namespace URLs to the root element.addNamespaceUrisToRoot(boolean value) Same asXmlSerializer.Builder.addNamespaceUrisToRoot()but allows you to explicitly specify the value.Add type attribute to root nodes.addRootType(boolean value) Same asSerializer.Builder.addRootType()but allows you to explicitly specify the value.HtmlSchemaSerializer configuration property: Allow nested descriptions.HtmlSchemaSerializer configuration property: Allow nested examples.annotations(Annotation... values) Defines annotations to apply to specific classes and methods.apply(AnnotationWorkList work) Applies a set of applied to this builder.applyAnnotations(Class<?>... from) Same asContext.Builder.applyAnnotations(Object...)but explicitly specifies a class varargs to avoid compilation warnings.applyAnnotations(Object... from) Applies any of the various@XConfig annotations on the specified classes or methods to this context.Aside section contents.asideFloat(AsideFloat value) Float aside section contents.beanClassVisibility(Visibility value) Minimum bean class visibility.Minimum bean constructor visibility.beanContext(BeanContext value) Specifies an already-instantiated bean context to use.beanContext(BeanContext.Builder value) Overrides the bean context builder.beanDefMapper(Class<? extends BeanDefMapper> value) HtmlSchemaSerializer configuration property: Schema definition mapper.beanDictionary(Class<?>... 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.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.Beans require Serializable interface.Beans require setters for getters.build()Build the object.Specifies a cache to use for hashkey-based caching.copy()Copy creator.debug()Context configuration property: Debug mode.debug(boolean value) Same asContext.Builder.debug()but allows you to explicitly specify the value.defaultNamespace(Namespace value) Default namespace.Automatically detect POJO recursions.detectRecursions(boolean value) Same asBeanTraverseContext.Builder.detectRecursions()but allows you to explicitly specify the value.dictionaryOn(Class<?> on, Class<?>... values) Bean dictionary.Don't auto-detect namespace usage.disableAutoDetectNamespaces(boolean value) Same asXmlSerializer.Builder.disableAutoDetectNamespaces()but allows you to explicitly specify the value.Beans don't require at least one property.HtmlSerializer configuration property: Dont look for link labels in URIs.disableDetectLabelParameters(boolean value) Same asHtmlSerializer.Builder.disableDetectLabelParameters()but allows you to explicitly specify the value.HtmlSerializer configuration property: Don't look for URLs inStrings.disableDetectLinksInStrings(boolean value) Same asHtmlSerializer.Builder.disableDetectLinksInStrings()but allows you to explicitly specify the value.Don't silently ignore missing setters.Don't ignore transient fields.Don't ignore unknown properties with null values.Don't use interface proxies.Enable support for XML namespaces.enableNamespaces(boolean value) Same asXmlSerializer.Builder.enableNamespaces()but allows you to explicitly specify the value.POJO example.POJO example.fileCharset(Charset value) File charset.Find fluent setters.findFluentSetters(Class<?> on) Find fluent setters.Footer section contents.Additional head section content.Header section contents.Ignore invocation errors on getters.Ignore invocation errors on setters.Ignore recursion errors.ignoreRecursions(boolean value) Same asBeanTraverseContext.Builder.ignoreRecursions()but allows you to explicitly specify the value.Ignore unknown properties.Ignore unknown enum values.Specifies a pre-instantiated bean for theContext.Builder.build()method to return.Implementation classes.implClasses(Map<Class<?>, Class<?>> values) Implementation classes.initialDepth(int value) Initial depth.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.Don't trim null bean property values.keepNullProperties(boolean value) Same asSerializer.Builder.keepNullProperties()but allows you to explicitly specify the value.labelParameter(String value) HtmlSerializer configuration property: Link label parameter name.listener(Class<? extends SerializerListener> value) Serializer listener.Context configuration property: Locale.maxDepth(int value) Max traversal depth.maxIndent(int value) Maximum indentation.Context configuration property: Media type.namespaces(Namespace... values) Default namespaces.Nav section contents.Page navigation links.noResultsMessage(String value) No-results message.notBeanClasses(Class<?>... values) Bean class exclusions.notBeanPackages(String... values) Bean package exclusions.nowrap()Prevent word wrap on page.nowrap(boolean value) Same asHtmlDocSerializer.Builder.nowrap()but allows you to explicitly specify the boolean value.ns()Enable support for XML namespaces.Specifies the media type that this serializer produces.propertyNamer(Class<?> on, Class<? extends PropertyNamer> value) Bean property namerpropertyNamer(Class<? extends PropertyNamer> value) Bean property namerquoteChar(char value) Quote character.quoteCharOverride(char value) Quote character override.Adds the specified Javascript code to the HTML page.Sort arrays and collections alphabetically.sortCollections(boolean value) Same asSerializer.Builder.sortCollections()but allows you to explicitly specify the value.sortMaps()Sort maps alphabetically.sortMaps(boolean value) Same asSerializer.Builder.sortMaps()but allows you to explicitly specify the value.Sort bean properties.sortProperties(Class<?>... on) Sort bean properties.sq()Quote character.Identifies a stop class for the annotated class.streamCharset(Charset value) Output stream charset.Adds the specified CSS instructions to the HTML page.stylesheet(String... value) Adds to the list of stylesheet URLs.swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction) A shortcut for defining aFunctionalSwap.swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction, ThrowingFunction<S, T> unswapFunction) A shortcut for defining aFunctionalSwap.Same asBeanContextable.Builder.swaps(Object...)except explicitly specifies class varargs to avoid compilation warnings.Java object swaps.template(Class<? extends HtmlDocTemplate> value) HTML document template.Context configuration property: TimeZone.Trim empty lists and arrays.trimEmptyCollections(boolean value) Same asSerializer.Builder.trimEmptyCollections()but allows you to explicitly specify the value.Trim empty maps.trimEmptyMaps(boolean value) Same asSerializer.Builder.trimEmptyMaps()but allows you to explicitly specify the value.Trim strings.trimStrings(boolean value) Same asSerializer.Builder.trimStrings()but allows you to explicitly specify the value.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.uriAnchorText(AnchorText value) HtmlSerializer configuration property: Anchor text source.uriContext(UriContext value) URI context bean.uriRelativity(UriRelativity value) URI relativity.uriResolution(UriResolution value) URI resolution.HtmlSchemaSerializer configuration property: Use bean definitions.Use enum names.Use Java Introspector.Use whitespace.useWhitespace(boolean value) Same asWriterSerializer.Builder.useWhitespace()but allows you to explicitly specify the value.widgets(Class<? extends HtmlWidget>... values) HTML Widgets.ws()Use whitespace.Methods inherited from class org.apache.juneau.html.HtmlDocSerializer.Builder
aside, footer, hashKey, head, header, nav, navlinks, resolveBodyVars, resolveBodyVars, script, style, stylesheet, widgetsMethods inherited from class org.apache.juneau.html.HtmlSerializer.Builder
disableJsonTags, disableJsonTags, textNodeDelimiterMethods inherited from class org.apache.juneau.serializer.Serializer.Builder
getAccept, getProducesMethods inherited from class org.apache.juneau.BeanContextable.Builder
beanContext, beanContextMethods inherited from class org.apache.juneau.Context.Builder
annotations, asSubtype, build, canApply, getApplied, getType, isDebug, registerBuilders
-
Constructor Details
-
Builder
protected Builder()Constructor, default settings. -
Builder
Copy constructor.- Parameters:
copyFrom- The builder to copy from.
-
Builder
Copy constructor.- Parameters:
copyFrom- The bean to copy from.
-
-
Method Details
-
accept
Description copied from class:Serializer.BuilderSpecifies the accept media types that the serializer can handle.Can contain meta-characters per the
media-type specification of RFC2616/14.1If empty, then assumes the only media type supported is
produces .For example, if this serializer produces
"application/json" but should handle media types of"application/json" and"text/json" , then the arguments should be:builder .produces("application/json" );builder .accept("application/json,text/json" );The accept value can also contain q-values.
- Overrides:
acceptin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.
Can benull (will default to the value specified bySerializer.Builder.produces(String)).- Returns:
- This object.
-
addBeanTypes
Description copied from class:Serializer.BuilderAdd"_type" properties when needed.When enabled,
"_type" properties will be added to beans if their type cannot be inferred through reflection.This is used to recreate the correct objects during parsing if the object types cannot be inferred.
For example, when serializing aMap<String,Object> field where the bean class cannot be determined from the type of the values.Note the differences between the following settings:
Serializer.Builder.addRootType()- Affects whether'_type' is added to root node.Serializer.Builder.addBeanTypes()- Affects whether'_type' is added to any nodes.
Example:
// Create a serializer that adds _type to nodes. WriterSerializerserializer = JsonSerializer .create () .addBeanTypes() .build();// Our map of beans to serialize. @Bean (typeName="mybean" )public class MyBean {public Stringfoo ="bar" ; } JsonMapmyMap = JsonMap.of("foo" ,new MyBean());// Will contain: {"foo":{"_type":"mybean","foo":"bar"}} Stringjson =serializer .serialize(myMap );- Overrides:
addBeanTypesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
addBeanTypes
Description copied from class:Serializer.BuilderSame asSerializer.Builder.addBeanTypes()but allows you to explicitly specify the value.- Overrides:
addBeanTypesin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
addBeanTypesHtml
Description copied from class:HtmlSerializer.BuilderAdd"_type" properties when needed.If
true , then"_type" properties will be added to beans if their type cannot be inferred through reflection.When present, this value overrides the
Serializer.Builder.addBeanTypes()setting and is provided to customize the behavior of specific serializers in aSerializerSet.- Overrides:
addBeanTypesHtmlin classHtmlDocSerializer.Builder- Returns:
- This object.
-
addBeanTypesHtml
Description copied from class:HtmlSerializer.BuilderSame asHtmlSerializer.Builder.addBeanTypesHtml()but allows you to explicitly specify the value.- Overrides:
addBeanTypesHtmlin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
addBeanTypesXml
Description copied from class:XmlSerializer.BuilderAdd"_type" properties when needed.If
true , then"_type" properties will be added to beans if their type cannot be inferred through reflection.When present, this value overrides the
Serializer.Builder.addBeanTypes()setting and is provided to customize the behavior of specific serializers in aSerializerSet.- Overrides:
addBeanTypesXmlin classHtmlDocSerializer.Builder- Returns:
- This object.
-
addBeanTypesXml
Description copied from class:XmlSerializer.BuilderSame asXmlSerializer.Builder.addBeanTypesXml()but allows you to explicitly specify the value.- Overrides:
addBeanTypesXmlin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
addDescriptionsTo
HtmlSchemaSerializer configuration property: Add descriptions.Identifies which categories of types that descriptions should be automatically added to generated schemas.
The description is the result of calling
ClassInfo.getName().See Also:
- Parameters:
values- The values to add to this setting.
The default is an empty string.- Returns:
- This object.
-
addExamplesTo
HtmlSchemaSerializer configuration property: Add examples.Identifies which categories of types that examples should be automatically added to generated schemas.
The examples come from calling
ClassMeta.getExample(BeanSession,JsonParserSession)which in turn gets examples from the following:See Also:
- Parameters:
values- The values to add to this setting.
The default is an empty string.- Returns:
- This object.
-
addKeyValueTableHeaders
Description copied from class:HtmlSerializer.BuilderHtmlSerializer configuration property: Add key/value headers on bean/map tables.When enabled,
key andvalue column headers are added to tables.Example:
// Our bean class. public class MyBean {public Stringf1 ="foo" ;public Stringf2 ="bar" ; }// Serializer without headers. WriterSerializerserializer1 = HtmlSerializer.DEFAULT ;// Serializer with headers. WriterSerializerserializer2 = HtmlSerializer .create () .addKeyValueTableHeaders() .build(); StringwithoutHeaders =serializer1 .serialize(new MyBean()); StringwithHeaders =serializer2 .serialize(new MyBean());The following shows the difference between the two generated outputs:
withoutHeaders withHeaders f1 foo f2 bar key value f1 foo f2 bar - Overrides:
addKeyValueTableHeadersin classHtmlDocSerializer.Builder- Returns:
- This object.
-
addKeyValueTableHeaders
Description copied from class:HtmlSerializer.BuilderSame asHtmlSerializer.Builder.addKeyValueTableHeaders()but allows you to explicitly specify the value.- Overrides:
addKeyValueTableHeadersin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
addNamespaceUrisToRoot
Description copied from class:XmlSerializer.BuilderAdd namespace URLs to the root element.Use this setting to add
xmlns:xattributes to the root element for the default and all mapped namespaces.This setting is ignored if
XmlSerializer.Builder.enableNamespaces()is not enabled.See Also:
- Overrides:
addNamespaceUrisToRootin classHtmlDocSerializer.Builder- Returns:
- This object.
-
addNamespaceUrisToRoot
Description copied from class:XmlSerializer.BuilderSame asXmlSerializer.Builder.addNamespaceUrisToRoot()but allows you to explicitly specify the value.- Overrides:
addNamespaceUrisToRootin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
addRootType
Description copied from class:Serializer.BuilderAdd type attribute to root nodes.When enabled,
"_type" properties will be added to top-level beans.When disabled, it is assumed that the parser knows the exact Java POJO type being parsed, and therefore top-level type information that might normally be included to determine the data type will not be serialized.
For example, when serializing a top-level POJO with a
@Bean(typeName)value, a'_type' attribute will only be added when this setting is enabled.Note the differences between the following settings:
Serializer.Builder.addRootType()- Affects whether'_type' is added to root node.Serializer.Builder.addBeanTypes()- Affects whether'_type' is added to any nodes.
Example:
// Create a serializer that adds _type to root node. WriterSerializerserializer = JsonSerializer .create () .addRootType() .build();// Our bean to serialize. @Bean (typeName="mybean" )public class MyBean {public Stringfoo ="bar" ; }// Will contain: {"_type":"mybean","foo":"bar"} Stringjson =serializer .serialize(new MyBean());- Overrides:
addRootTypein classHtmlDocSerializer.Builder- Returns:
- This object.
-
addRootType
Description copied from class:Serializer.BuilderSame asSerializer.Builder.addRootType()but allows you to explicitly specify the value.- Overrides:
addRootTypein classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
allowNestedDescriptions
HtmlSchemaSerializer configuration property: Allow nested descriptions.Identifies whether nested descriptions are allowed in schema definitions.
See Also:
- Returns:
- This object.
-
allowNestedExamples
HtmlSchemaSerializer configuration property: Allow nested examples.Identifies whether nested examples are allowed in schema definitions.
See Also:
- Returns:
- This object.
-
annotations
Description copied from class:Context.BuilderDefines annotations to apply to specific classes and methods.Allows you to dynamically apply Juneau annotations typically applied directly to classes and methods. Useful in cases where you want to use the functionality of the annotation on beans and bean properties but do not have access to the code to do so.
As a rule, any Juneau annotation with an
on() method can be used with this setting.The following example shows the equivalent methods for applying the
@Beanannotation:// Class with explicit annotation. @Bean (properties="street,city,state" )public class A {...}// Class with annotation applied via @BeanConfig public class B {...}// Java REST method with @BeanConfig annotation. @RestGet (...)@Bean (on="B" , properties="street,city,state" )public void doFoo() {...}In general, the underlying framework uses this method when it finds dynamically applied annotations on config annotations. However, concrete implementations of annotations are also provided that can be passed directly into builder classes like so:
// Create a concrete @Bean annotation. Bean annotation = BeanAnnotation.create (B.class ).properties("street,city,state" ).build();// Apply it to a serializer. WriterSerializerserializer = JsonSerializer.create ().annotations(annotation ).build();// Serialize a bean with the dynamically applied annotation. Stringjson =serializer .serialize(new B());The following is the list of annotations builders provided that can be constructed and passed into the builder class:
BeanAnnotationBeancAnnotationBeanIgnoreAnnotationBeanpAnnotationExampleAnnotationNamePropertyAnnotationParentPropertyAnnotationSwapAnnotationUriAnnotationCsvAnnotationHtmlAnnotationJsonAnnotationSchemaAnnotationMsgPackAnnotationOpenApiAnnotationPlainTextAnnotationSoapXmlAnnotationUonAnnotationUrlEncodingAnnotationXmlAnnotation
The syntax for the
on() pattern match parameter depends on whether it applies to a class, method, field, or constructor. The valid pattern matches are:- Classes:
- Fully qualified:
"com.foo.MyClass"
- Fully qualified inner class:
"com.foo.MyClass$Inner1$Inner2"
- Simple:
"MyClass"
- Simple inner:
"MyClass$Inner1$Inner2" "Inner1$Inner2" "Inner2"
- Fully qualified:
- Methods:
- Fully qualified with args:
"com.foo.MyClass.myMethod(String,int)" "com.foo.MyClass.myMethod(java.lang.String,int)" "com.foo.MyClass.myMethod()"
- Fully qualified:
"com.foo.MyClass.myMethod"
- Simple with args:
"MyClass.myMethod(String,int)" "MyClass.myMethod(java.lang.String,int)" "MyClass.myMethod()"
- Simple:
"MyClass.myMethod"
- Simple inner class:
"MyClass$Inner1$Inner2.myMethod" "Inner1$Inner2.myMethod" "Inner2.myMethod"
- Fully qualified with args:
- Fields:
- Fully qualified:
"com.foo.MyClass.myField"
- Simple:
"MyClass.myField"
- Simple inner class:
"MyClass$Inner1$Inner2.myField" "Inner1$Inner2.myField" "Inner2.myField"
- Fully qualified:
- Constructors:
- Fully qualified with args:
"com.foo.MyClass(String,int)" "com.foo.MyClass(java.lang.String,int)" "com.foo.MyClass()"
- Simple with args:
"MyClass(String,int)" "MyClass(java.lang.String,int)" "MyClass()"
- Simple inner class:
"MyClass$Inner1$Inner2()" "Inner1$Inner2()" "Inner2()"
- Fully qualified with args:
- A comma-delimited list of anything on this list.
See Also:
- Overrides:
annotationsin classHtmlDocSerializer.Builder- Parameters:
values- The annotations to register with the context.
Cannot containnull values.- Returns:
- This object.
-
apply
Description copied from class:Context.BuilderApplies a set of applied to this builder.An
AnnotationWorkconsists of a single pair ofAnnotationInfothat represents an annotation instance, andAnnotationApplierwhich represents the code used to apply the values in that annotation to a specific builder.Example:
// A class annotated with a config annotation. @BeanConfig (sortProperties="$S{sortProperties,false}" )public class MyClass {...}// Find all annotations that themselves are annotated with @ContextPropertiesApply. Stream<AnnotationInfo<?>>annotations = ClassInfo.of (MyClass.class ).getAnnotations().stream().filter(CONTEXT_APPLY_FILTER ); VarResolverSessionvrs = VarResolver.DEFAULT .createSession(); AnnotationWorkListwork = AnnotationWorkList.of(vrs ,annotations );// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .apply(work ) .build();- Overrides:
applyin classHtmlDocSerializer.Builder- Parameters:
work- The list of annotations and appliers to apply to this builder.
Cannot benull .- Returns:
- This object.
-
applyAnnotations
Description copied from class:Context.BuilderSame asContext.Builder.applyAnnotations(Object...)but explicitly specifies a class varargs to avoid compilation warnings.- Overrides:
applyAnnotationsin classHtmlDocSerializer.Builder- Parameters:
from- The classes or methods on which the annotations are defined.
Cannot containnull values.- Returns:
- This object.
-
applyAnnotations
Description copied from class:Context.BuilderApplies any of the various@XConfig annotations on the specified classes or methods to this context.Any annotations found that themselves are annotated with
ContextApplywill be resolved and applied as properties to this builder. These annotations include:BeanConfigCsvConfigHtmlConfigHtmlDocConfigJsonConfigJsonSchemaConfigMsgPackConfigOpenApiConfigParserConfigPlainTextConfigSerializerConfigSoapXmlConfigUonConfigUrlEncodingConfigXmlConfigRdfConfig
Annotations on classes are appended in the following order:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
Annotations on methods are appended in the following order:
- On the package of the method class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On the method class.
- On this method and matching methods ordered parent-to-child.
The default var resolver
VarResolver.DEFAULTis used to resolve any variables in annotation field values.Example:
// A class annotated with a config annotation. @BeanConfig (sortProperties="$S{sortProperties,false}" )public class MyClass {...}// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .applyAnnotations(MyClass.class ) .build();// A method annotated with a config annotation. public class MyClass {@BeanConfig (sortProperties="$S{sortProperties,false}" )public void myMethod() {...} }// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .applyAnnotations(MyClass.class .getMethod("myMethod" )) .build();- Overrides:
applyAnnotationsin classHtmlDocSerializer.Builder- Parameters:
from- The classes or methods on which the annotations are defined. Can be any of the following types:ClassClassInfoMethodMethodInfo- A collection/stream/array of anything on this list.
Cannot containnull values.
- Returns:
- This object.
-
aside
Description copied from class:HtmlDocSerializer.BuilderAside section contents.Allows you to specify the contents of the aside section on the HTML page. The aside section floats on the right of the page for providing content supporting the serialized content of the page.
By default, the aside section is empty.
Example:
WriterSerializer
serializer = HtmlDocSerializer .create () .aside("<ul>" ," <li>Item 1" ," <li>Item 2" ," <li>Item 3" ,"</ul>" ) .build();Notes:
- Format: HTML
-
Supports SVL Variables
(e.g.
"$L{my.localized.variable}" ). -
A value of
"NONE" can be used to force no value. -
The parent value can be included by adding the literal
"INHERIT" as a value. - Multiple values are combined with newlines into a single string.
-
On methods, this value is inherited from the
@HtmlDocConfig annotation on the servlet/resource class. -
On servlet/resource classes, this value is inherited from the
@HtmlDocConfig annotation on the parent class.
- Overrides:
asidein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.- Returns:
- This object.
-
asideFloat
Description copied from class:HtmlDocSerializer.BuilderFloat aside section contents.Allows you to position the aside contents of the page around the main contents.
By default, the aside section is floated to the right.
Example:
WriterSerializer
serializer = HtmlDocSerializer .create () .aside("<ul>" ," <li>Item 1" ," <li>Item 2" ," <li>Item 3" ,"</ul>" ) .asideFloat(RIGHT ) .build();- Overrides:
asideFloatin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.- Returns:
- This object.
-
beanClassVisibility
Description copied from class:BeanContextable.BuilderMinimum 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 .serialize(new MyBean());Notes:
- The
@Beanannotation 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:
- Overrides:
beanClassVisibilityin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC.
Cannot benull .- Returns:
- This object.
- The
-
beanConstructorVisibility
Description copied from class:BeanContextable.BuilderMinimum 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. MyBeanbean =parser .parse("{foo:'bar'}" , MyBean.class );Notes:
- The
@Beancannotation 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:
- Overrides:
beanConstructorVisibilityin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC.
Cannot benull .- Returns:
- This object.
- The
-
beanContext
Description copied from class:BeanContextable.BuilderSpecifies an already-instantiated bean context to use.Provides an optimization for cases where serializers and parsers can use an existing bean context without having to go through
. An example isbeanContext .copy().build()BeanContext.getBeanToStringSerializer().- Overrides:
beanContextin classHtmlDocSerializer.Builder- Parameters:
value- The bean context to use.
Cannot benull .- Returns:
- This object.
-
beanContext
Description copied from class:BeanContextable.BuilderOverrides the bean context builder.Used when sharing bean context builders across multiple context objects. For example,
JsonSchemaGenerator.Builderuses this to apply common bean settings with the JSON serializer and parser.- Overrides:
beanContextin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
Cannot benull .- Returns:
- This object.
-
beanDefMapper
HtmlSchemaSerializer configuration property: Schema definition mapper.Interface to use for converting Bean classes to definition IDs and URIs.
Used primarily for defining common definition sections for beans in Swagger JSON.
This setting is ignored if
JsonSchemaGenerator.Builder.useBeanDefs()is not enabled.See Also:
- Parameters:
value- The new value for this property.
The default isBasicBeanDefMapper.- Returns:
- This object.
-
beanDictionary
Description copied from class:BeanContextable.BuilderBean 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
@Bean(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
@Bean(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 @Bean(name) annotations. @Bean (typeName="foo" )public class Foo {...}@Bean (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. MyBeanbean =parser .parse("{mySimpleField:{_type:'foo',...}}" , MyBean.class );Another option is to use the
Bean.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. @Bean (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 .parse("<body><ul><li>foo</li><li>bar</li></ul>" , Body.class );See Also:
- Overrides:
beanDictionaryin classHtmlDocSerializer.Builder- Parameters:
values- The values to add to this setting.
Cannot containnull values.- Returns:
- This object.
- Any bean class that specifies a value for
-
beanFieldVisibility
Description copied from class:BeanContextable.BuilderMinimum 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 .serialize(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
@Beanpannotation 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:
- Overrides:
beanFieldVisibilityin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC.
Cannot benull .- Returns:
- This object.
- The
-
beanInterceptor
public HtmlSchemaDocSerializer.Builder beanInterceptor(Class<?> on, Class<? extends BeanInterceptor<?>> value) Description copied from class:BeanContextable.BuilderBean 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 .serialize(new Address());See Also:
- Overrides:
beanInterceptorin classHtmlDocSerializer.Builder- Parameters:
on- The bean that the filter applies to.
Cannot benull .value- The new value for this setting.
Cannot benull .- Returns:
- This object.
-
beanMapPutReturnsOldValue
Description copied from class:BeanContextable.BuilderBeanMap.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. BeanContextcontext = BeanContext .create () .beanMapPutReturnsOldValue() .build(); BeanMap<MyBean>beanMap =context .createSession().toBeanMap(new MyBean());beanMap .put("foo" ,"bar" ); ObjectoldValue =beanMap .put("foo" ,"baz" );// oldValue == "bar" See Also:
- Overrides:
beanMapPutReturnsOldValuein classHtmlDocSerializer.Builder- Returns:
- This object.
-
beanMethodVisibility
Description copied from class:BeanContextable.BuilderMinimum 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 .serialize(new MyBean());Notes:
- The
@Beanpannotation 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:
- Overrides:
beanMethodVisibilityin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default isVisibility.PUBLIC
Cannot benull .- Returns:
- This object.
- The
-
beanProperties
Description copied from class:BeanContextable.BuilderBean 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 whetherBeanContextable.Builder.ignoreUnknownBeanProperties()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 .serialize(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClass ).properties(properties ).build());See Also:
Bean.properties()/Bean.p()- On an annotation on the bean class itself.
- Overrides:
beanPropertiesin classHtmlDocSerializer.Builder- Parameters:
beanClass- The bean class.properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanProperties
Description copied from class:BeanContextable.BuilderBean 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 whetherBeanContextable.Builder.ignoreUnknownBeanProperties()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 .serialize(new MyBean());This method is functionally equivalent to the following code for each entry:
builder .annotations(BeanAnnotation.create (key ).properties(value .toString()).build());See Also:
Bean.properties()/Bean.p()- On an annotation on the bean class itself.
- Overrides:
beanPropertiesin classHtmlDocSerializer.Builder- 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
Description copied from class:BeanContextable.BuilderBean 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 whetherBeanContextable.Builder.ignoreUnknownBeanProperties()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 .serialize(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClassName ).properties(properties ).build());See Also:
Bean.properties()/Bean.p()- On an annotation on the bean class itself.
- Overrides:
beanPropertiesin classHtmlDocSerializer.Builder- Parameters:
beanClassName- The bean class name.
Can be a simple name, fully-qualified name, or"*" for all beans.
Cannot benull .properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesExcludes
public HtmlSchemaDocSerializer.Builder beanPropertiesExcludes(Class<?> beanClass, String properties) Description copied from class:BeanContextable.BuilderBean property excludes.Specifies to exclude the specified list of properties for the specified bean class.
Same as
BeanContextable.Builder.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 .serialize(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClass ).excludeProperties(properties ).build());See Also:
- Overrides:
beanPropertiesExcludesin classHtmlDocSerializer.Builder- Parameters:
beanClass- The bean class.properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesExcludes
Description copied from class:BeanContextable.BuilderBean property excludes.Specifies to exclude the specified list of properties for the specified bean classes.
Same as
BeanContextable.Builder.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 .serialize(new MyBean());This method is functionally equivalent to the following code for each entry:
builder .annotations(BeanAnnotation.create (key ).excludeProperties(value .toString()).build());See Also:
- Overrides:
beanPropertiesExcludesin classHtmlDocSerializer.Builder- 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
public HtmlSchemaDocSerializer.Builder beanPropertiesExcludes(String beanClassName, String properties) Description copied from class:BeanContextable.BuilderBean property excludes.Specifies to exclude the specified list of properties for the specified bean class.
Same as
BeanContextable.Builder.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 .serialize(new MyBean());This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClassName ).excludeProperties(properties ).build());See Also:
- Overrides:
beanPropertiesExcludesin classHtmlDocSerializer.Builder- 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
public HtmlSchemaDocSerializer.Builder beanPropertiesReadOnly(Class<?> beanClass, String properties) Description copied from class:BeanContextable.BuilderRead-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 .serialize(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. MyBeanbean =parser .parse("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClass ).readOnlyProperties(properties ).build());See Also:
- Overrides:
beanPropertiesReadOnlyin classHtmlDocSerializer.Builder- Parameters:
beanClass- The bean class.properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesReadOnly
Description copied from class:BeanContextable.BuilderRead-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 .serialize(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. MyBeanbean =parser .parse("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code for each entry:
builder .annotations(BeanAnnotation.create (key ).readOnlyProperties(value .toString()).build());See Also:
- Overrides:
beanPropertiesReadOnlyin classHtmlDocSerializer.Builder- 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
public HtmlSchemaDocSerializer.Builder beanPropertiesReadOnly(String beanClassName, String properties) Description copied from class:BeanContextable.BuilderRead-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 .serialize(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. MyBeanbean =parser .parse("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClassName ).readOnlyProperties(properties ).build());See Also:
- Overrides:
beanPropertiesReadOnlyin classHtmlDocSerializer.Builder- 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.
-
beanPropertiesWriteOnly
public HtmlSchemaDocSerializer.Builder beanPropertiesWriteOnly(Class<?> beanClass, String properties) Description copied from class:BeanContextable.BuilderWrite-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 .serialize(new MyBean());// Create a parser with write-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesWriteOnly(MyBean.class ,"bar,baz" ) .build();// Parser parses all 3 properties. MyBeanbean =parser .parse("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClass ).writeOnlyProperties(properties ).build());See Also:
- Overrides:
beanPropertiesWriteOnlyin classHtmlDocSerializer.Builder- Parameters:
beanClass- The bean class.properties- Comma-delimited list of property names.
Cannot benull .- Returns:
- This object.
-
beanPropertiesWriteOnly
Description copied from class:BeanContextable.BuilderWrite-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 .serialize(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. MyBeanbean =parser .parse("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code for each entry:
builder .annotations(BeanAnnotation.create (key ).writeOnlyProperties(value .toString()).build());See Also:
- Overrides:
beanPropertiesWriteOnlyin classHtmlDocSerializer.Builder- 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
public HtmlSchemaDocSerializer.Builder beanPropertiesWriteOnly(String beanClassName, String properties) Description copied from class:BeanContextable.BuilderWrite-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 .serialize(new MyBean());// Create a parser with write-only property settings. ReaderParserparser = JsonParser .create () .beanPropertiesWriteOnly("MyBean" ,"bar,baz" ) .build();// Parser parses all 3 properties. MyBeanbean =parser .parse("{foo:'foo',bar:'bar',baz:'baz'}" , MyBean.class );This method is functionally equivalent to the following code:
builder .annotations(BeanAnnotation.create (beanClassName ).writeOnlyProperties(properties ).build());See Also:
- Overrides:
beanPropertiesWriteOnlyin classHtmlDocSerializer.Builder- 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.
-
beansRequireDefaultConstructor
Description copied from class:BeanContextable.BuilderBeans 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 .serialize(new MyBean());Notes:
- The
@Beanannotation 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:
- Overrides:
beansRequireDefaultConstructorin classHtmlDocSerializer.Builder- Returns:
- This object.
- The
-
beansRequireSerializable
Description copied from class:BeanContextable.BuilderBeans 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 .serialize(new MyBean());Notes:
- The
@Beanannotation 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:
- Overrides:
beansRequireSerializablein classHtmlDocSerializer.Builder- Returns:
- This object.
- The
-
beansRequireSettersForGetters
Description copied from class:BeanContextable.BuilderBeans 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 .serialize(new MyBean());Notes:
- The
@Beanpannotation can be used on the getter to override this setting. - The
@BeanIgnoreannotation can also be used on getters to ignore them as bean properties.
See Also:
- Overrides:
beansRequireSettersForGettersin classHtmlDocSerializer.Builder- Returns:
- This object.
- The
-
build
Description copied from class:Context.BuilderBuild the object.- Overrides:
buildin classHtmlDocSerializer.Builder- Returns:
- The built object.
-
cache
Description copied from class:Context.BuilderSpecifies a cache to use for hashkey-based caching.When a cache is specified, contexts with the same hash key will be reused from the cache instead of creating new instances. This improves performance when building multiple contexts with identical configurations.
If
null is specified, caching is disabled and each call toContext.Builder.build()will create a new context instance.- Overrides:
cachein classHtmlDocSerializer.Builder- Parameters:
value- The cache.
Can benull (disables caching, each build creates a new instance).- Returns:
- This object.
-
copy
Description copied from class:Context.BuilderCopy creator.- Overrides:
copyin classHtmlDocSerializer.Builder- Returns:
- A new mutable copy of this builder.
-
debug
Description copied from class:Context.BuilderContext configuration property: Debug mode.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
BeanTraverseContext.Builder.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. WriterSerializerserializer = JsonSerializer .create () .debug() .build();// Create a POJO model with a recursive loop. public class MyBean {public Objectf ; } MyBeanbean =new MyBean();bean .f =bean ;// Throws a SerializeException and not a StackOverflowError Stringjson =serializer .serialize(bean );See Also:
- Overrides:
debugin classHtmlDocSerializer.Builder- Returns:
- This object.
-
debug
Description copied from class:Context.BuilderSame asContext.Builder.debug()but allows you to explicitly specify the value.- Overrides:
debugin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
defaultNamespace
Description copied from class:XmlSerializer.Builder- Overrides:
defaultNamespacein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default is"juneau: http://www.apache.org/2013/Juneau" .
Can benull to specify no namespace.- Returns:
- This object.
-
detectRecursions
Description copied from class:BeanTraverseContext.BuilderAutomatically detect POJO recursions.When enabled, specifies that recursions should be checked for during traversal.
Recursions can occur when traversing models that aren't true trees but rather contain loops.
In general, unchecked recursions cause stack-overflow-errors.
These show up asBeanRecursionExceptionwith the message"Depth too deep. Stack overflow occurred." .Notes:
- Checking for recursion can cause a small performance penalty.
Example:
// Create a serializer that automatically checks for recursions. WriterSerializerserializer = JsonSerializer .create () .detectRecursions() .build();// Create a POJO model with a recursive loop. public class MyBean {public Objectf ; } MyBeanbean =new MyBean();bean .f =bean ;// Throws a SerializeException and not a StackOverflowError Stringjson =serializer .serialize(bean );- Overrides:
detectRecursionsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
detectRecursions
Description copied from class:BeanTraverseContext.BuilderSame asBeanTraverseContext.Builder.detectRecursions()but allows you to explicitly specify the value.- Overrides:
detectRecursionsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
dictionaryOn
Description copied from class:BeanContextable.BuilderBean dictionary.This is identical to
BeanContextable.Builder.beanDictionary(Class...), but specifies a dictionary within the context of a single class as opposed to globally.Example:
// POJOs with @Bean(name) annotations. @Bean (typeName="foo" )public class Foo {...}@Bean (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. MyBeanbean =parser .parse("{mySimpleField:{_type:'foo',...}}" , MyBean.class );This is functionally equivalent to the
Bean.dictionary()annotation.See Also:
- Overrides:
dictionaryOnin classHtmlDocSerializer.Builder- Parameters:
on- The class that the dictionary values apply to.
Cannot benull .values- The new values for this setting.
Cannot containnull values.- Returns:
- This object.
-
disableAutoDetectNamespaces
Description copied from class:XmlSerializer.BuilderDon't auto-detect namespace usage.Don't detect namespace usage before serialization.
Used in conjunction with
XmlSerializer.Builder.addNamespaceUrisToRoot()to reduce the list of namespace URLs appended to the root element to only those that will be used in the resulting document.If disabled, then the data structure will first be crawled looking for namespaces that will be encountered before the root element is serialized.
This setting is ignored if
XmlSerializer.Builder.enableNamespaces()is not enabled.Notes:
-
Auto-detection of namespaces can be costly performance-wise.
In high-performance environments, it's recommended that namespace detection be disabled, and that namespaces be manually defined through theXmlSerializer.Builder.namespaces(Namespace...)property.
See Also:
- Overrides:
disableAutoDetectNamespacesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
Auto-detection of namespaces can be costly performance-wise.
-
disableAutoDetectNamespaces
Description copied from class:XmlSerializer.BuilderSame asXmlSerializer.Builder.disableAutoDetectNamespaces()but allows you to explicitly specify the value.- Overrides:
disableAutoDetectNamespacesin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
disableBeansRequireSomeProperties
Description copied from class:BeanContextable.BuilderBeans 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
@Beanannotation 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 .serialize(new MyBean());Notes:
- The
@Beanannotation can be used on the class to force it to be recognized as a bean class even if it has no properties.
See Also:
- Overrides:
disableBeansRequireSomePropertiesin classHtmlDocSerializer.Builder- Returns:
- This object.
- The
-
disableDetectLabelParameters
Description copied from class:HtmlSerializer.BuilderHtmlSerializer configuration property: Dont look for link labels in URIs.Disables the feature where if the URL has a label parameter (e.g.
"?label=foobar" ), then use that as the anchor text of the link.The parameter name can be changed via the
HtmlSerializer.Builder.labelParameter(String)property.Example:
// Our bean class with a property containing what looks like a URL. public class MyBean {public URIf1 = URI.create ("http://www.apache.org?label=Apache%20Foundation" ); }// Serializer with label detection. WriterSerializerserializer1 = HtmlSerializer .create () .addKeyValueTableHeaders() .build();// Serializer without label detection. WriterSerializerserializer2 = HtmlSerializer .create () .addKeyValueTableHeaders() .disableDetectLabelParameters() .build(); StringwithLabels =serializer1 .serialize(new MyBean()); StringwithoutLabels =serializer2 .serialize(new MyBean());The following shows the difference between the two generated outputs.
Note that they're both hyperlinks, but the anchor text differs:withLabels withoutLabels key value f1 Apache Foundation key value f1 http://www.apache.org?label=Apache%20Foundation - Overrides:
disableDetectLabelParametersin classHtmlDocSerializer.Builder- Returns:
- This object.
-
disableDetectLabelParameters
Description copied from class:HtmlSerializer.BuilderSame asHtmlSerializer.Builder.disableDetectLabelParameters()but allows you to explicitly specify the value.- Overrides:
disableDetectLabelParametersin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
disableDetectLinksInStrings
Description copied from class:HtmlSerializer.BuilderHtmlSerializer configuration property: Don't look for URLs inStrings.Disables the feature where if a string looks like a URL (i.e. starts with
"http://" or"https://" , then treat it like a URL and make it into a hyperlink based on the rules specified byHtmlSerializer.Builder.uriAnchorText(AnchorText).Example:
// Our bean class with a property containing what looks like a URL. public class MyBean {public Stringf1 ="http://www.apache.org" ; }// Serializer with link detection. WriterSerializerserializer1 = HtmlSerializer .create () .addKeyValueTableHeaders() .build();// Serializer without link detection. WriterSerializerserializer2 = HtmlSerializer .create () .addKeyValueTableHeaders() .disableDetectLinksInStrings() .build(); StringwithLinks =serializer1 .serialize(new MyBean()); StringwithoutLinks =serializer2 .serialize(new MyBean());The following shows the difference between the two generated outputs:
withLinks withoutLinks key value f1 http://www.apache.org key value f1 http://www.apache.org - Overrides:
disableDetectLinksInStringsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
disableDetectLinksInStrings
Description copied from class:HtmlSerializer.BuilderSame asHtmlSerializer.Builder.disableDetectLinksInStrings()but allows you to explicitly specify the value.- Overrides:
disableDetectLinksInStringsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
disableIgnoreMissingSetters
Description copied from class:BeanContextable.BuilderDon'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. MyBeanbean =parser .parse("{foo:'bar'}" , MyBean.class );Notes:
- The
@BeanIgnoreannotation can also be used on getters and fields to ignore them.
See Also:
- Overrides:
disableIgnoreMissingSettersin classHtmlDocSerializer.Builder- Returns:
- This object.
- The
-
disableIgnoreTransientFields
Description copied from class:BeanContextable.BuilderDon'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 .serialize(new MyBean());Notes:
- The
@Beanpannotation can also be used on transient fields to keep them from being ignored.
See Also:
- Overrides:
disableIgnoreTransientFieldsin classHtmlDocSerializer.Builder- Returns:
- This object.
- The
-
disableIgnoreUnknownNullBeanProperties
Description copied from class:BeanContextable.BuilderDon'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. MyBeanbean =parser .parse("{foo:'foo',bar:null}" , MyBean.class );See Also:
- Overrides:
disableIgnoreUnknownNullBeanPropertiesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
disableInterfaceProxies
Description copied from class:BeanContextable.BuilderDon'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:
- Overrides:
disableInterfaceProxiesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
enableNamespaces
Description copied from class:XmlSerializer.BuilderEnable support for XML namespaces.If not enabled, XML output will not contain any namespaces regardless of any other settings.
See Also:
- Overrides:
enableNamespacesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
enableNamespaces
Description copied from class:XmlSerializer.BuilderSame asXmlSerializer.Builder.enableNamespaces()but allows you to explicitly specify the value.- Overrides:
enableNamespacesin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
example
Description copied from class:BeanContextable.BuilderPOJO 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 oneBeanSessionargument. - A static method with name
example with no arguments or oneBeanSessionargument.
See Also:
- Overrides:
examplein classHtmlDocSerializer.Builder- 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
Description copied from class:BeanContextable.BuilderPOJO 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 oneBeanSessionargument. - A static method with name
example with no arguments or oneBeanSessionargument.
- Overrides:
examplein classHtmlDocSerializer.Builder- 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.
-
fileCharset
Description copied from class:WriterSerializer.BuilderFile charset.The character set to use for writing
Files to the file system.Used when passing in files to
Serializer.serialize(Object, Object).Example:
// Create a serializer that writes UTF-8 files. WriterSerializerserializer = JsonSerializer .create () .fileCharset(Charset.forName ("UTF-8" )) .build();// Use it to read a UTF-8 encoded file. serializer .serialize(new File("MyBean.txt" ),myBean );- Overrides:
fileCharsetin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default is the system JVM setting.
Can benull (defaults to system default).- Returns:
- This object.
-
findFluentSetters
Description copied from class:BeanContextable.BuilderFind 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. MyBeanbean =parser .parse("{foo:'bar'}" , MyBean.class );Notes:
- The
@Beanpannotation can also be used on methods to individually identify them as fluent setters. - The
@Bean.fluentSetters()annotation can also be used on classes to specify to look for fluent setters.
See Also:
- Overrides:
findFluentSettersin classHtmlDocSerializer.Builder- Returns:
- This object.
-
findFluentSetters
Description copied from class:BeanContextable.BuilderFind fluent setters.Identical to
BeanContextable.Builder.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. MyBeanbean =parser .parse("{foo:'bar'}" , MyBean.class );Notes:
- This method is functionally equivalent to using the
Bean.findFluentSetters()annotation.
See Also:
- Overrides:
findFluentSettersin classHtmlDocSerializer.Builder- Parameters:
on- The class that this applies to.
Cannot benull .- Returns:
- This object.
- This method is functionally equivalent to using the
-
head
Description copied from class:HtmlDocSerializer.BuilderAdditional head section content.Adds the specified HTML content to the head section of the page.
Example:
WriterSerializer
serializer = HtmlDocSerializer .create () .head("<link rel='icon' href='$U{servlet:/htdocs/mypageicon.ico}'>" ) .build();- Overrides:
headin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.- Returns:
- This object.
-
header
Description copied from class:HtmlDocSerializer.BuilderHeader section contents.Allows you to override the contents of the header section on the HTML page. The header section normally contains the title and description at the top of the page.
Example:
WriterSerializer
serializer = HtmlDocSerializer .create () .header("<h1>My own header</h1>" ) .build()- Overrides:
headerin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.- Returns:
- This object.
-
ignoreInvocationExceptionsOnGetters
Description copied from class:BeanContextable.BuilderIgnore 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 .serialize(new MyBean());See Also:
- Overrides:
ignoreInvocationExceptionsOnGettersin classHtmlDocSerializer.Builder- Returns:
- This object.
-
ignoreInvocationExceptionsOnSetters
Description copied from class:BeanContextable.BuilderIgnore 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. MyBeanbean =parser .parse("{foo:'bar'}" , MyBean.class );See Also:
- Overrides:
ignoreInvocationExceptionsOnSettersin classHtmlDocSerializer.Builder- Returns:
- This object.
-
ignoreRecursions
Description copied from class:BeanTraverseContext.BuilderIgnore recursion errors.When enabled, when we encounter the same object when traversing a tree, we set the value to
null .For example, if a model contains the links A->B->C->A, then the JSON generated will look like the following when this setting is
true ...{A:{B:{C:
null }}}Notes:
- Checking for recursion can cause a small performance penalty.
Example:
// Create a serializer ignores recursions. WriterSerializerserializer = JsonSerializer .create () .ignoreRecursions() .build();// Create a POJO model with a recursive loop. public class MyBean {public Objectf ; } MyBeanbean =new MyBean();bean .f =bean ;// Produces "{f:null}" Stringjson =serializer .serialize(bean );- Overrides:
ignoreRecursionsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
ignoreRecursions
Description copied from class:BeanTraverseContext.BuilderSame asBeanTraverseContext.Builder.ignoreRecursions()but allows you to explicitly specify the value.- Overrides:
ignoreRecursionsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
ignoreUnknownBeanProperties
Description copied from class:BeanContextable.BuilderIgnore 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. MyBeanbean =parser .parse("{foo:'foo',bar:'bar'}" , MyBean.class );See Also:
- Overrides:
ignoreUnknownBeanPropertiesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
ignoreUnknownEnumValues
Description copied from class:BeanContextable.BuilderIgnore unknown enum values.When enabled, unknown enum values are set to
null instead of throwing a parse exception.See Also:
- Overrides:
ignoreUnknownEnumValuesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
impl
Description copied from class:Context.BuilderSpecifies a pre-instantiated bean for theContext.Builder.build()method to return.If a non-null value is provided and it's an instance of the context type,
Context.Builder.build()will return that instance instead of creating a new one. Ifnull , the normal build process continues.- Overrides:
implin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.
Can benull (normal build process will continue).- Returns:
- This object.
-
implClass
Description copied from class:BeanContextable.BuilderImplementation 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, MyBeanbean =parser .parse("..." , MyBean.class );- Overrides:
implClassin classHtmlDocSerializer.Builder- Parameters:
interfaceClass- The interface class.
Cannot benull .implClass- The implementation class.
Cannot benull .- Returns:
- This object.
-
implClasses
Description copied from class:BeanContextable.BuilderImplementation 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, MyBeanbean =parser .parse("..." , MyBean.class );- Overrides:
implClassesin classHtmlDocSerializer.Builder- Parameters:
values- The new value for this setting.
Cannot benull .- Returns:
- This object.
-
initialDepth
Description copied from class:BeanTraverseContext.BuilderInitial depth.The initial indentation level at the root.
Useful when constructing document fragments that need to be indented at a certain level when whitespace is enabled.
Example:
// Create a serializer with whitespace enabled and an initial depth of 2. WriterSerializerserializer = JsonSerializer .create () .ws() .initialDepth(2) .build();// Produces "\t\t{\n\t\t\t'foo':'bar'\n\t\t}\n" Stringjson =serializer .serialize(new MyBean());- Overrides:
initialDepthin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default is0 .- Returns:
- This object.
-
interfaceClass
Description copied from class:BeanContextable.BuilderIdentifies 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 .serialize(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
@Bean(interfaceClass)annotation is the equivalent annotation-based solution.
- Overrides:
interfaceClassin classHtmlDocSerializer.Builder- 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
Description copied from class:BeanContextable.BuilderIdentifies 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 .serialize(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
@Bean(interfaceClass)annotation is the equivalent annotation-based solution.
- Overrides:
interfacesin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
Cannot containnull values.- Returns:
- This object.
- The
-
keepNullProperties
Description copied from class:Serializer.BuilderDon't trim null bean property values.When enabled, null bean values will be serialized to the output.
Notes:
- Not enabling this setting will cause
Map s withnull values to be lost during parsing.
Example:
// Create a serializer that serializes null properties. WriterSerializerserializer = JsonSerializer .create () .keepNullProperties() .build();// Our bean to serialize. public class MyBean {public Stringfoo =null ; }// Will contain "{foo:null}". Stringjson =serializer .serialize(new MyBean());- Overrides:
keepNullPropertiesin classHtmlDocSerializer.Builder- Returns:
- This object.
- Not enabling this setting will cause
-
keepNullProperties
Description copied from class:Serializer.BuilderSame asSerializer.Builder.keepNullProperties()but allows you to explicitly specify the value.- Overrides:
keepNullPropertiesin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
labelParameter
Description copied from class:HtmlSerializer.BuilderHtmlSerializer configuration property: Link label parameter name.The parameter name to look for when resolving link labels}.
- Overrides:
labelParameterin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
Cannot benull .
The default is"label" .- Returns:
- This object.
-
listener
Description copied from class:Serializer.BuilderSerializer listener.Class used to listen for errors and warnings that occur during serialization.
Example:
// Define our serializer listener. // Simply captures all errors. public class MySerializerListenerextends SerializerListener {// A simple property to store our events. public List<String>events =new LinkedList<>();@Override public <T>void onError(SerializerSessionsession , Throwablethrowable , Stringmsg ) {events .add(session .getLastLocation() +"," +msg +"," +throwable ); } }// Create a serializer using our listener. WriterSerializerserializer = JsonSerializer .create () .listener(MySerializerListener.class ) .build();// Create a session object. // Needed because listeners are created per-session. try (WriterSerializerSessionsession =serializer .createSession()) {// Serialize a bean. Stringjson =session .serialize(new MyBean());// Get the listener. MySerializerListenerlistener =session .getListener(MySerializerListener.class );// Dump the results to the console. Json5.DEFAULT .println(listener .events ); }- Overrides:
listenerin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
Can benull (no listener will be used, listener methods will not be called).- Returns:
- This object.
-
locale
Description copied from class:BeanContextable.BuilderContext configuration property: Locale.Specifies the default locale for serializer and parser sessions when not specified via
BeanSession.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(BeanSession, Object)andObjectSwap.unswap(BeanSession, 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(BeanSessionsession , 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:
- Overrides:
localein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
Cannot benull .- Returns:
- This object.
-
maxDepth
Description copied from class:BeanTraverseContext.BuilderMax traversal depth.When enabled, abort traversal if specified depth is reached in the POJO tree.
If this depth is exceeded, an exception is thrown.
This prevents stack overflows from occurring when trying to traverse models with recursive references.
Example:
// Create a serializer that throws an exception if the depth reaches greater than 20. WriterSerializerserializer = JsonSerializer .create () .maxDepth(20) .build();See Also:
- Overrides:
maxDepthin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default is100 .- Returns:
- This object.
-
maxIndent
Description copied from class:WriterSerializer.BuilderMaximum indentation.Specifies the maximum indentation level in the serialized document.
Notes:
- This setting does not apply to the RDF serializers.
Example:
// Create a serializer that indents a maximum of 20 tabs. WriterSerializerserializer = JsonSerializer .create () .ws()// Enable whitespace .maxIndent(20) .build();- Overrides:
maxIndentin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default is100 .- Returns:
- This object.
-
mediaType
Description copied from class:BeanContextable.BuilderContext configuration property: Media type.Specifies the default media type for serializer and parser sessions when not specified via
BeanSession.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(BeanSessionsession , 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:
- Overrides:
mediaTypein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
Can benull (no default media type will be set).- Returns:
- This object.
-
namespaces
Description copied from class:XmlSerializer.BuilderDefault namespaces.The default list of namespaces associated with this serializer.
- Overrides:
namespacesin classHtmlDocSerializer.Builder- Parameters:
values- The new value for this property.
Cannot containnull values.- Returns:
- This object.
-
noResultsMessage
Description copied from class:HtmlDocSerializer.BuilderNo-results message.Allows you to specify the string message used when trying to serialize an empty array or empty list.
Example:
WriterSerializer
serializer = HtmlDocSerializer .create () .noResultsMessage("<b>This interface is great!</b>" ) .build();A value of
"NONE" can be used to represent no value to differentiate it from an empty string.- Overrides:
noResultsMessagein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.- Returns:
- This object.
-
notBeanClasses
Description copied from class:BeanContextable.BuilderBean 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 .serialize(new MyBean());Notes:
- The
@BeanIgnoreannotation can also be used on classes to prevent them from being recognized as beans.
See Also:
- Overrides:
notBeanClassesin classHtmlDocSerializer.Builder- Parameters:
values- The values to add to this setting.
Values can consist of any of the following types:- Classes.
- Arrays and collections of classes.
Cannot containnull values.- Returns:
- This object.
-
notBeanPackages
Description copied from class:BeanContextable.BuilderBean package exclusions.Used as a convenient way of defining the
BeanContext.Builder.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();See Also:
- Overrides:
notBeanPackagesin classHtmlDocSerializer.Builder- 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.
-
nowrap
Description copied from class:HtmlDocSerializer.BuilderPrevent word wrap on page.Adds
"* {white-space:nowrap}" to the CSS instructions on the page to prevent word wrapping.- Overrides:
nowrapin classHtmlDocSerializer.Builder- Returns:
- This object.
-
nowrap
Description copied from class:HtmlDocSerializer.BuilderSame asHtmlDocSerializer.Builder.nowrap()but allows you to explicitly specify the boolean value.- Overrides:
nowrapin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.- Returns:
- This object.
- See Also:
-
ns
Description copied from class:XmlSerializer.BuilderEnable support for XML namespaces.Shortcut for calling
enableNamespaces(.true )- Overrides:
nsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
produces
Description copied from class:Serializer.BuilderSpecifies the media type that this serializer produces.- Overrides:
producesin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.
Can benull .- Returns:
- This object.
-
propertyNamer
public HtmlSchemaDocSerializer.Builder propertyNamer(Class<?> on, Class<? extends PropertyNamer> value) Description copied from class:BeanContextable.BuilderBean property namerSame as
BeanContextable.Builder.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 .serialize(new MyBean());See Also:
- Overrides:
propertyNamerin classHtmlDocSerializer.Builder- 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
Description copied from class:BeanContextable.BuilderBean 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 .serialize(new MyBean());See Also:
- Overrides:
propertyNamerin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default isBasicPropertyNamer.
Cannot benull .- Returns:
- This object.
-
quoteChar
Description copied from class:WriterSerializer.BuilderQuote character.Specifies the character to use for quoting attributes and values.
Notes:
- This setting does not apply to the RDF serializers.
Example:
// Create a serializer that uses single quotes. WriterSerializerserializer = JsonSerializer .create () .quoteChar('\'' ) .build();// A bean with a single property public class MyBean {public Stringfoo ="bar" ; }// Produces {'foo':'bar'} Stringjson =serializer .toString(new MyBean());- Overrides:
quoteCharin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default is'"' .- Returns:
- This object.
-
quoteCharOverride
Description copied from class:WriterSerializer.BuilderQuote character override.Similar to
WriterSerializer.Builder.quoteChar(char)but takes precedence over that setting.Allows you to override the quote character even if it's set by a subclass such as
Json5Serializer.- Overrides:
quoteCharOverridein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default isnull .- Returns:
- This object.
-
script
Description copied from class:HtmlDocSerializer.BuilderAdds the specified Javascript code to the HTML page.A shortcut on
@Rest is also provided for this setting:WriterSerializer
serializer = HtmlDocSerializer .create () .script("alert('hello!');" ) .build();- Overrides:
scriptin classHtmlDocSerializer.Builder- Parameters:
value- The value to add to this property.- Returns:
- This object.
-
sortCollections
Description copied from class:Serializer.BuilderSort arrays and collections alphabetically.When enabled, copies and sorts the contents of arrays and collections before serializing them.
Note that this introduces a performance penalty since it requires copying the existing collection.
Example:
// Create a serializer that sorts arrays and collections before serialization. WriterSerializerserializer = JsonSerializer .create () .sortCollections() .build();// An unsorted array String[]myArray = {"foo" ,"bar" ,"baz" };// Produces ["bar","baz","foo"] Stringjson =serializer .serialize(myArray );- Overrides:
sortCollectionsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
sortCollections
Description copied from class:Serializer.BuilderSame asSerializer.Builder.sortCollections()but allows you to explicitly specify the value.- Overrides:
sortCollectionsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
sortMaps
Description copied from class:Serializer.BuilderSort maps alphabetically.When enabled, copies and sorts the contents of maps by their keys before serializing them.
Note that this introduces a performance penalty.
Example:
// Create a serializer that sorts maps before serialization. WriterSerializerserializer = JsonSerializer .create () .sortMaps() .build();// An unsorted map. JsonMapmyMap = JsonMap.of ("foo" ,1,"bar" ,2,"baz" ,3);// Produces {"bar":2,"baz":3,"foo":1} Stringjson =serializer .serialize(myMap );- Overrides:
sortMapsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
sortMaps
Description copied from class:Serializer.BuilderSame asSerializer.Builder.sortMaps()but allows you to explicitly specify the value.- Overrides:
sortMapsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
sortProperties
Description copied from class:BeanContextable.BuilderSort bean properties.When enabled, 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 setting is disabled by default so that IBM JVM users don't have to use
@Beanannotations 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:
// A bean with 3 properties. public class MyBean {public Stringc ="1" ;public Stringb ="2" ;public Stringa ="3" ; }// Create a serializer that sorts bean properties. WriterSerializerserializer = JsonSerializer .create () .sortProperties() .build();// Produces: {"a":"3","b":"2","c":"1"} Stringjson =serializer .serialize(new MyBean());Notes:
- The
@Bean.sort()annotation can also be used to sort properties on just a single class.
See Also:
- Overrides:
sortPropertiesin classHtmlDocSerializer.Builder- Returns:
- This object.
- The
-
sortProperties
Description copied from class:BeanContextable.BuilderSort bean properties.Same as
BeanContextable.Builder.sortProperties()but allows you to specify individual bean classes instead of globally.Example:
// A bean with 3 properties. public class MyBean {public Stringc ="1" ;public Stringb ="2" ;public Stringa ="3" ; }// Create a serializer that sorts properties on MyBean. WriterSerializerserializer = JsonSerializer .create () .sortProperties(MyBean.class ) .build();// Produces: {"a":"3","b":"2","c":"1"} Stringjson =serializer .serialize(new MyBean());See Also:
- Overrides:
sortPropertiesin classHtmlDocSerializer.Builder- Parameters:
on- The bean classes to sort properties on.
Cannot containnull values.- Returns:
- This object.
-
sq
Description copied from class:WriterSerializer.BuilderQuote character.Specifies to use single quotes for quoting attributes and values.
Notes:
- This setting does not apply to the RDF serializers.
Example:
// Create a serializer that uses single quotes. WriterSerializerserializer = JsonSerializer .create () .sq() .build();// A bean with a single property public class MyBean {public Stringfoo ="bar" ; }// Produces {'foo':'bar'} Stringjson =serializer .toString(new MyBean());- Overrides:
sqin classHtmlDocSerializer.Builder- Returns:
- This object.
-
stopClass
Description copied from class:BeanContextable.BuilderIdentifies 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 .serialize(new C3());- Overrides:
stopClassin classHtmlDocSerializer.Builder- 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.
-
streamCharset
Description copied from class:WriterSerializer.BuilderOutput stream charset.The character set to use when writing to
OutputStreams .Used when passing in output streams and byte arrays to
Serializer.serialize(Object, Object).Example:
// Create a serializer that writes UTF-8 files. WriterSerializerserializer = JsonSerializer .create () .streamCharset(Charset.forName ("UTF-8" )) .build();// Use it to write to a UTF-8 encoded output stream. serializer .serializer(new FileOutputStreamStream("MyBean.txt" ),myBean );- Overrides:
streamCharsetin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default is the system JVM setting.
Can benull (defaults to UTF-8).- Returns:
- This object.
-
style
Description copied from class:HtmlDocSerializer.BuilderAdds the specified CSS instructions to the HTML page.WriterSerializer
serializer = HtmlDocSerializer .create () .style("h3 { color: red; }" ,"h5 { font-weight: bold; }" ) .build();- Overrides:
stylein classHtmlDocSerializer.Builder- Parameters:
value- The value to add to this property.- Returns:
- This object.
-
stylesheet
Description copied from class:HtmlDocSerializer.BuilderAdds to the list of stylesheet URLs.Note that this stylesheet is controlled by the
annotation.@Rest .stylesheet()- Overrides:
stylesheetin classHtmlDocSerializer.Builder- Parameters:
value- The value to add to this property.- Returns:
- This object.
-
swap
public <T,S> HtmlSchemaDocSerializer.Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction) Description copied from class:BeanContextable.BuilderA 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();- Overrides:
swapin classHtmlDocSerializer.Builder- 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> HtmlSchemaDocSerializer.Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T, S> swapFunction, ThrowingFunction<S, T> unswapFunction) Description copied from class:BeanContextable.BuilderA 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();- Overrides:
swapin classHtmlDocSerializer.Builder- 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
Description copied from class:BeanContextable.BuilderSame asBeanContextable.Builder.swaps(Object...)except explicitly specifies class varargs to avoid compilation warnings.- Overrides:
swapsin classHtmlDocSerializer.Builder- 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 containnull values.- Any subclass of
- Returns:
- This object.
-
swaps
Description copied from class:BeanContextable.BuilderJava 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(BeanSessionsession , Datedate ) {return format .format(date ); }@Override public Date unswap(BeanSessionsession , 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 .serialize(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 .parse(json , MyBean.class );Notes:
- The
@Swapannotation can also be used on classes to identify swaps for the class. - The
@Swapannotation can also be used on bean methods and fields to identify swaps for values of those bean properties.
See Also:
- Overrides:
swapsin classHtmlDocSerializer.Builder- 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 containnull values.- Any subclass of
- Returns:
- This object.
- Any subclass of
-
template
Description copied from class:HtmlDocSerializer.BuilderHTML document template.Specifies the template to use for serializing the page.
By default, the
BasicHtmlDocTemplateclass is used to construct the contents of the HTML page, but can be overridden with your own custom implementation class.Example:
WriterSerializer
serializer = HtmlDocSerializer .create () .template(MySpecialDocTemplate.class ) .build();- Overrides:
templatein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.- Returns:
- This object.
-
timeZone
Description copied from class:BeanContextable.BuilderContext configuration property: TimeZone.Specifies the default time zone for serializer and parser sessions when not specified via
BeanSession.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(BeanSession, Object)andObjectSwap.unswap(BeanSession, 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(BeanSessionsession , 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:
- Overrides:
timeZonein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
Can benull (timezone will not be set, defaults to system timezone).- Returns:
- This object.
-
trimEmptyCollections
Description copied from class:Serializer.BuilderTrim empty lists and arrays.When enabled, empty lists and arrays will not be serialized.
Note that enabling this setting has the following effects on parsing:
- Map entries with empty list values will be lost.
- Bean properties with empty list values will not be set.
Example:
// Create a serializer that skips empty arrays and collections. WriterSerializerserializer = JsonSerializer .create () .trimEmptyCollections() .build();// A bean with a field with an empty array. public class MyBean {public String[]foo = {}; }// Produces {} Stringjson =serializer .serialize(new MyBean());- Overrides:
trimEmptyCollectionsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
trimEmptyCollections
Description copied from class:Serializer.BuilderSame asSerializer.Builder.trimEmptyCollections()but allows you to explicitly specify the value.- Overrides:
trimEmptyCollectionsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
trimEmptyMaps
Description copied from class:Serializer.BuilderTrim empty maps.When enabled, empty map values will not be serialized to the output.
Note that enabling this setting has the following effects on parsing:
- Bean properties with empty map values will not be set.
Example:
// Create a serializer that skips empty maps. WriterSerializerserializer = JsonSerializer .create () .trimEmptyMaps() .build();// A bean with a field with an empty map. public class MyBean {public JsonMapfoo = JsonMap.of (); }// Produces {} Stringjson =serializer .serialize(new MyBean());- Overrides:
trimEmptyMapsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
trimEmptyMaps
Description copied from class:Serializer.BuilderSame asSerializer.Builder.trimEmptyMaps()but allows you to explicitly specify the value.- Overrides:
trimEmptyMapsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
trimStrings
Description copied from class:Serializer.BuilderTrim strings.When enabled, string values will be trimmed of whitespace using
String.trim()before being serialized.Example:
// Create a serializer that trims strings before serialization. WriterSerializerserializer = JsonSerializer .create () .trimStrings() .build();// A map with space-padded keys/values JsonMapmyMap = JsonMap.of (" foo " ," bar " );// Produces "{foo:'bar'}" Stringjson =serializer .toString(myMap );- Overrides:
trimStringsin classHtmlDocSerializer.Builder- Returns:
- This object.
-
trimStrings
Description copied from class:Serializer.BuilderSame asSerializer.Builder.trimStrings()but allows you to explicitly specify the value.- Overrides:
trimStringsin classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- 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 classHtmlDocSerializer.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
Description copied from class:BeanContextable.BuilderAn 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 .serialize(new MyBean());Notes:
- Equivalent to the
Bean(typeName)annotation.
See Also:
- Overrides:
typeNamein classHtmlDocSerializer.Builder- Parameters:
on- The class the type name is being defined on.value- The new value for this setting.
Cannot benull .- Returns:
- This object.
- Equivalent to the
-
typePropertyName
Description copied from class:BeanContextable.BuilderBean type property name.Same as
BeanContextable.Builder.typePropertyName(String)except targets a specific bean class instead of globally.Example:
// POJOs with @Bean(name) annotations. @Bean (typeName="foo" )public class Foo {...}@Bean (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 .serialize(new MyBean());See Also:
- Overrides:
typePropertyNamein classHtmlDocSerializer.Builder- Parameters:
on- The class the type property name applies to.value- The new value for this setting.
The default is"_type" .
Cannot benull .- Returns:
- This object.
-
typePropertyName
Description copied from class:BeanContextable.BuilderBean 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 @Bean(name) annotations. @Bean (typeName="foo" )public class Foo {...}@Bean (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 .serialize(new MyBean());// Parse bean. MyBeanbean =parser .parse(json , MyBean.class );See Also:
- Overrides:
typePropertyNamein classHtmlDocSerializer.Builder- Parameters:
value- The new value for this setting.
The default is"_type" .
Cannot benull .- Returns:
- This object.
-
uriAnchorText
Description copied from class:HtmlSerializer.BuilderHtmlSerializer configuration property: Anchor text source.When creating anchor tags (e.g.
) in HTML, this setting defines what to set the inner text to.<a href ='...' > text</a> The possible values are:
AnchorTextTO_STRING(default) - Set to whatever is returned byObject.toString()on the object.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("http://www.apache.org?foo=bar#myAnchor" ); }// Serializer with TO_STRING anchor text. WriterSerializerserializer1 = HtmlSerializer.create ().anchorText(TO_STRING ).build();// Produces: <a href='http://www.apache.org?foo=bar#myAnchor'>http://www.apache.org?foo=bar#myAnchor</a> Stringhtml =serializer1 .serialize(new MyBean());PROPERTY_NAME- Set to the bean property name.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("http://www.apache.org?foo=bar#myAnchor" ); }// Serializer with PROPERTY_NAME anchor text. WriterSerializerserializer1 = HtmlSerializer.create ().anchorText(PROPERTY_NAME ).build();// Produces: <a href='http://www.apache.org?foo=bar#myAnchor'>f1</a> Stringhtml =serializer1 .serialize(new MyBean());URI- Set to the URI value.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("http://www.apache.org?foo=bar#myAnchor" ); }// Serializer with URI anchor text. WriterSerializerserializer1 = HtmlSerializer.create ().anchorText(URI ).build();// Produces: <a href='http://www.apache.org?foo=bar#myAnchor'>http://www.apache.org?foo=bar</a> Stringhtml =serializer1 .serialize(new MyBean());LAST_TOKEN- Set to the last token of the URI value.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("http://www.apache.org/foo/bar?baz=qux#myAnchor" ); }// Serializer with LAST_TOKEN anchor text. WriterSerializerserializer1 = HtmlSerializer.create ().anchorText(LAST_TOKEN ).build();// Produces: <a href='http://www.apache.org/foo/bar?baz=qux#myAnchor'>bar</a> Stringhtml =serializer1 .serialize(new MyBean());URI_ANCHOR- Set to the anchor of the URL.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("http://www.apache.org/foo/bar?baz=qux#myAnchor" ); }// Serializer with URI_ANCHOR anchor text. WriterSerializerserializer1 = HtmlSerializer.create ().anchorText(URI_ANCHOR ).build();// Produces: <a href='http://www.apache.org/foo/bar?baz=qux#myAnchor'>myAnchor</a> Stringhtml =serializer1 .serialize(new MyBean());CONTEXT_RELATIVE- Same asTO_STRINGbut assumes it's a context-relative path.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("bar/baz" ); }// Serializer with CONTEXT_RELATIVE anchor text. WriterSerializerserializer1 = HtmlSerializer .create () .anchorText(CONTEXT_RELATIVE ) .uriResolution(ROOT_RELATIVE ) .uriRelativity(RESOURCE ) .uriContext("{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}" ) .build();// Produces: <a href='/myContext/myServlet/bar/baz'>myServlet/bar/baz</a> Stringhtml =serializer1 .serialize(new MyBean());SERVLET_RELATIVE- Same asTO_STRINGbut assumes it's a servlet-relative path.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("bar/baz" ); }// Serializer with SERVLET_RELATIVE anchor text. WriterSerializerserializer1 = HtmlSerializer .create () .anchorText(SERVLET_RELATIVE ) .uriResolution(ROOT_RELATIVE ) .uriRelativity(RESOURCE ) .uriContext("{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}" ) .build();// Produces: <a href='/myContext/myServlet/bar/baz'>bar/baz</a> Stringhtml =serializer1 .serialize(new MyBean());PATH_RELATIVE- Same asTO_STRINGbut assumes it's a path-relative path.
Example:
// Our bean class with a URI property. public class MyBean {public URIf1 = URI.create ("bar/baz" ); }// Serializer with PATH_RELATIVE anchor text. WriterSerializerserializer1 = HtmlSerializer .create () .anchorText(PATH_RELATIVE ) .uriResolution(ROOT_RELATIVE ) .uriRelativity(PATH_INFO ) .uriContext("{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}" ) .build();// Produces: <a href='/myContext/myServlet/foo/bar/baz'>bar/baz</a> Stringhtml =serializer1 .serialize(new MyBean());
- Overrides:
uriAnchorTextin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
Cannot benull .
The default isAnchorText.TO_STRING.- Returns:
- This object.
-
uriContext
Description copied from class:Serializer.BuilderURI context bean.Bean used for resolution of URIs to absolute or root-relative form.
Example:
// Our URI contextual information. Stringauthority ="http://localhost:10000" ; StringcontextRoot ="/myContext" ; StringservletPath ="/myServlet" ; StringpathInfo ="/foo" ;// Create a UriContext object. UriContexturiContext =new UriContext(authority ,contextRoot ,servletPath ,pathInfo );// Associate it with our serializer. WriterSerializerserializer = JsonSerializer .create () .uriContext(uriContext ) .uriRelativity(RESOURCE )// Assume relative paths are relative to servlet. .uriResolution(ABSOLUTE )// Serialize URLs as absolute paths. .build();// A relative URL URLmyUrl =new URL("bar" );// Produces "http://localhost:10000/myContext/myServlet/foo/bar" Stringjson =serializer .toString(myUrl );See Also:
- Overrides:
uriContextin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
Can benull (defaults toUriContext.DEFAULT ).- Returns:
- This object.
-
uriRelativity
Description copied from class:Serializer.BuilderURI relativity.Defines what relative URIs are relative to when serializing any of the following:
See
Serializer.Builder.uriContext(UriContext)for examples.UriRelativity.RESOURCE- Relative URIs should be considered relative to the servlet URI.UriRelativity.PATH_INFO- Relative URIs should be considered relative to the request URI.
See Also:
- Overrides:
uriRelativityin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default isUriRelativity.RESOURCE
Can benull (defaults toUriRelativity.RESOURCE ).- Returns:
- This object.
-
uriResolution
Description copied from class:Serializer.BuilderURI resolution.Defines the resolution level for URIs when serializing any of the following:
See
Serializer.Builder.uriContext(UriContext)for examples.UriResolution.ABSOLUTE- Resolve to an absolute URL (e.g."http://host:port/context-root/servlet-path/path-info" ).UriResolution.ROOT_RELATIVE- Resolve to a root-relative URL (e.g."/context-root/servlet-path/path-info" ).UriResolution.NONE- Don't do any URL resolution.
See Also:
- Overrides:
uriResolutionin classHtmlDocSerializer.Builder- Parameters:
value- The new value for this property.
The default isUriResolution.NONE
Can benull (defaults toUriResolution.NONE ).- Returns:
- This object.
-
useBeanDefs
HtmlSchemaSerializer configuration property: Use bean definitions.When enabled, schemas on beans will be serialized as the following:
{ type:
'object' ,'$ref' :'#/definitions/TypeId' }- Returns:
- This object.
-
useEnumNames
Description copied from class:BeanContextable.BuilderUse enum names.When enabled, enums are always serialized by name, not using
Object.toString().Example:
// Create a serializer with debug enabled. WriterSerializerserializer = JsonSerializer .create () .useEnumNames() .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 value ; Option(int value ) {this .value =value ; }@Override public String toString() {return String.valueOf (value ); } }See Also:
- Overrides:
useEnumNamesin classHtmlDocSerializer.Builder- Returns:
- This object.
-
useJavaBeanIntrospector
Description copied from class:BeanContextable.BuilderUse Java Introspector.Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters.
Most@Beanannotations will be ignored.Example:
// Create a serializer that only uses the built-in java bean introspector for finding properties. WriterSerializerserializer = JsonSerializer .create () .useJavaBeanIntrospector() .build();See Also:
- Overrides:
useJavaBeanIntrospectorin classHtmlDocSerializer.Builder- Returns:
- This object.
-
useWhitespace
Description copied from class:WriterSerializer.BuilderUse whitespace.When enabled, whitespace is added to the output to improve readability.
Example:
// Create a serializer with whitespace enabled. WriterSerializerserializer = JsonSerializer .create () .useWhitespace() .build();// A bean with a single property public class MyBean {public Stringfoo ="bar" ; }// Produces "\{\n\t"foo": "bar"\n\}\n" Stringjson =serializer .serialize(new MyBean());- Overrides:
useWhitespacein classHtmlDocSerializer.Builder- Returns:
- This object.
-
useWhitespace
Description copied from class:WriterSerializer.BuilderSame asWriterSerializer.Builder.useWhitespace()but allows you to explicitly specify the value.- Overrides:
useWhitespacein classHtmlDocSerializer.Builder- Parameters:
value- The value for this setting.- Returns:
- This object.
-
widgets
Description copied from class:HtmlDocSerializer.BuilderHTML Widgets.Defines widgets that can be used in conjunction with string variables of the form
"$W{name}" to quickly generate arbitrary replacement text. Widgets resolve the following variables:"$W{name}" - Contents returned byHtmlWidget.getHtml(VarResolverSession)."$W{name.script}" - Contents returned byHtmlWidget.getScript(VarResolverSession).
The script contents are automatically inserted into the<head/script> section in the HTML page."$W{name.style}" - Contents returned byHtmlWidget.getStyle(VarResolverSession).
The styles contents are automatically inserted into the<head/style> section in the HTML page.
The following examples shows how to associate a widget with a REST method and then have it rendered in the links and aside section of the page:
WriterSerializer
serializer = HtmlDocSerializer .create () .widgets( MyWidget.class ) .navlinks("$W{MyWidget}" ) .aside("Check out this widget: $W{MyWidget}" ) .build();Notes:
- Widgets are inherited from super classes, but can be overridden by reusing the widget name.
See Also:
- Overrides:
widgetsin classHtmlDocSerializer.Builder- Parameters:
values- The values to add to this setting.- Returns:
- This object.
-
ws
Description copied from class:WriterSerializer.BuilderUse whitespace.When enabled, whitespace is added to the output to improve readability.
Example:
// Create a serializer with whitespace enabled. WriterSerializerserializer = JsonSerializer .create () .ws() .build();// A bean with a single property public class MyBean {public Stringfoo ="bar" ; }// Produces "\{\n\t"foo": "bar"\n\}\n" Stringjson =serializer .serialize(new MyBean());- Overrides:
wsin classHtmlDocSerializer.Builder- Returns:
- This object.
-