Class Config.Builder
- Enclosing class:
- Config
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor, default settings.protectedCopy constructor.protectedBuilder(Config.Builder copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionannotations(Annotation... values) Defines annotations to apply to specific classes and methods.annotations(List<Annotation> values) Same asContext.Builder.annotations(Annotation...)but uses a list as input.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.binaryFormat(BinaryFormat value) Binary value format.binaryLineLength(int value) Binary value line length.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.Specifies a pre-instantiated bean for theContext.Builder.build()method to return.memStore()Configuration store.Adds a value modifier.Multi-line values on separate lines.Configuration name.parser(ReaderParser value) POJO parser.readOnly()Read-only mode.serializer(WriterSerializer value) POJO serializer.store(ConfigStore value) Configuration store.Associates a context class with this builder.varResolver(VarResolver value) SVL variable resolver.Methods inherited from class org.apache.juneau.Context.Builder
asSubtype, build, canApply, getApplied, getType, hashKey, 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
-
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 classContext.Builder- Parameters:
values- The annotations to register with the context.
Cannot containnull values.- Returns:
- This object.
-
annotations
Description copied from class:Context.BuilderSame asContext.Builder.annotations(Annotation...)but uses a list as input.- Overrides:
annotationsin classContext.Builder- Parameters:
values- The annotations to register with the context.
Cannot benull or 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 classContext.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 classContext.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 classContext.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.
-
binaryFormat
Binary value format.The format to use when persisting byte arrays.
BinaryFormat.BASE64- BASE64-encoded string.BinaryFormat.HEX- Hexadecimal.BinaryFormat.SPACED_HEX- Hexadecimal with spaces between bytes.
- Parameters:
value- The new value for this property.
The default is the first value found:- System property
"Config.binaryFormat" - Environment variable
"CONFIG_BINARYFORMAT" BinaryFormat.BASE64 - Environment variable
Cannot benull .- System property
- Returns:
- This object.
-
binaryLineLength
Binary value line length.When serializing binary values, lines will be split after this many characters.
Use-1 to represent no line splitting.- Parameters:
value- The new value for this property.
The default is the first value found:- System property
"Config.binaryLineLength" - Environment variable
"CONFIG_BINARYLINELENGTH" -1 - Environment variable
- System property
- Returns:
- This object.
-
build
Description copied from class:Context.BuilderBuild the object.- Overrides:
buildin classContext.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 classContext.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.- Specified by:
copyin classContext.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 classContext.Builder- Returns:
- This object.
-
debug
Description copied from class:Context.BuilderSame asContext.Builder.debug()but allows you to explicitly specify the value.- Overrides:
debugin classContext.Builder- Parameters:
value- The value for this setting.- 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 classContext.Builder- Parameters:
value- The value for this setting.
Can benull (normal build process will continue).- Returns:
- This object.
-
memStore
Configuration store.Convenience method for calling
store(ConfigMemoryStore..DEFAULT )- Returns:
- This object.
-
mods
Adds a value modifier.Modifiers are used to modify entry value before being persisted.
- Parameters:
values- The mods to apply to this config.
Cannot containnull values.- Returns:
- This object.
-
multiLineValuesOnSeparateLines
Multi-line values on separate lines.When enabled, multi-line values will always be placed on a separate line from the key.
The default is the first value found:
- System property
"Config.multiLineValuesOnSeparateLine" - Environment variable
"CONFIG_MULTILINEVALUESONSEPARATELINE" false - Environment variable
- Returns:
- This object.
- System property
-
name
Configuration name.Specifies the configuration name.
This is typically the configuration file name, although the name can be anything identifiable by theConfigStoreused for retrieving and storing the configuration.- Parameters:
value- The new value for this property.
The default is the first value found:- System property
"Config.name" - Environment variable
"CONFIG_NAME" "Configuration.cfg" - Environment variable
Cannot benull .- System property
- Returns:
- This object.
-
parser
POJO parser.The parser to use for parsing values to POJOs.
- Parameters:
value- The new value for this property.
The default isJsonParser.DEFAULT.
Cannot benull .- Returns:
- This object.
-
readOnly
Read-only mode.When enabled, attempts to call any setters on this object will throw an
UnsupportedOperationException.The default is the first value found:
- System property
"Config.readOnly" - Environment variable
"CONFIG_READONLY" false - Environment variable
- Returns:
- This object.
- System property
-
serializer
POJO serializer.The serializer to use for serializing POJO values.
- Parameters:
value- The new value for this property.
The default isJson5Serializer.DEFAULT
Cannot benull .- Returns:
- This object.
-
store
Configuration store.The configuration store used for retrieving and storing configurations.
- Parameters:
value- The new value for this property.
The default isFileStore.DEFAULT.
Cannot benull .- Returns:
- This object.
-
type
Description copied from class:Context.BuilderAssociates a context class with this builder.This is the type of object that this builder creates when the
Context.Builder.build()method is called.By default, it's the outer class of where the builder class is defined.
If
null is set,Context.Builder.build()will throw an exception. The default constructor automatically sets this to the outer class, sonull should only be set explicitly if you want to override the default.- Overrides:
typein classContext.Builder- Parameters:
value- The context class that this builder should create.
Can benull (will causeContext.Builder.build()to throw an exception).- Returns:
- This object.
-
varResolver
SVL variable resolver.The resolver to use for resolving SVL variables.
- Parameters:
value- The new value for this property.
The default isVarResolver.DEFAULT.
Cannot benull .- Returns:
- This object.
-