public class RestContextBuilder extends BeanContextBuilder implements ServletConfig
An extension of the ServletConfig
object used during servlet initialization.
Provides access to the following initialized resources:
getConfig()
- The external configuration for this resource.
getProperties()
- The modifiable configuration properties for this resource.
getVarResolverBuilder()
- The variable resolver for this resource.
Methods are provided for overriding or augmenting the information provided by the
To interact with this object, simply pass it in as a constructor argument or in an INIT hook.
Modifier and Type | Method and Description |
---|---|
RestContextBuilder |
add(Map<String,Object> properties)
Adds multiple free-form configuration properties on this object without first clearing out any previous values.
|
RestContextBuilder |
addTo(String name,
Object value)
Adds a free-form value to a SET property.
|
RestContextBuilder |
allowBodyParam(boolean value)
|
RestContextBuilder |
allowedHeaderParams(String value)
|
RestContextBuilder |
allowedMethodHeaders(String value)
|
RestContextBuilder |
allowedMethodParams(String value)
|
RestContextBuilder |
allowHeaderParams(boolean value)
Deprecated.
|
RestContextBuilder |
annotations(Annotation... values)
|
RestContextBuilder |
appendTo(String name,
Object value)
Adds a free-form value to the end of a LIST property.
|
RestContextBuilder |
apply(PropertyStore copyFrom)
Copies the settings from the specified property store into this builder.
|
RestContextBuilder |
applyAnnotations(AnnotationList al,
VarResolverSession r)
Applies a set of annotations to this property store.
|
RestContextBuilder |
applyAnnotations(Class<?>... fromClasses)
Applies any of the various
|
RestContextBuilder |
applyAnnotations(Method... fromMethods)
Applies any of the various
|
RestContextBuilder |
attr(String name,
Object value)
Deprecated.
|
RestContextBuilder |
attrs(String... values)
Deprecated.
|
RestContextBuilder |
beanClassVisibility(Visibility value)
|
RestContextBuilder |
beanConstructorVisibility(Visibility value)
|
RestContextBuilder |
beanFieldVisibility(Visibility value)
|
RestContextBuilder |
beanInterceptor(Class<?> on,
Class<? extends BeanInterceptor<?>> value)
Bean interceptor.
|
RestContextBuilder |
beanMapPutReturnsOldValue()
|
RestContextBuilder |
beanMethodVisibility(Visibility value)
|
RestContextBuilder |
beansDontRequireSomeProperties()
|
RestContextBuilder |
beansRequireDefaultConstructor()
|
RestContextBuilder |
beansRequireSerializable()
|
RestContextBuilder |
beansRequireSettersForGetters()
|
RestContextBuilder |
bpi(Class<?> beanClass,
String properties)
Bean property includes.
|
RestContextBuilder |
bpi(Map<String,Object> values)
Bean property includes.
|
RestContextBuilder |
bpi(String beanClassName,
String properties)
Bean property includes.
|
RestContextBuilder |
bpro(Class<?> beanClass,
String properties)
Read-only bean properties.
|
RestContextBuilder |
bpro(Map<String,Object> values)
Read-only bean properties.
|
RestContextBuilder |
bpro(String beanClassName,
String properties)
Read-only bean properties.
|
RestContextBuilder |
bpwo(Class<?> beanClass,
String properties)
Write-only bean properties.
|
RestContextBuilder |
bpwo(Map<String,Object> values)
Write-only bean properties.
|
RestContextBuilder |
bpwo(String beanClassName,
String properties)
Write-only bean properties.
|
RestContextBuilder |
bpx(Class<?> beanClass,
String properties)
Bean property excludes.
|
RestContextBuilder |
bpx(Map<String,Object> values)
Bean property excludes.
|
RestContextBuilder |
bpx(String beanClassName,
String properties)
Bean property excludes.
|
RestContext |
build()
Build the object.
|
RestContextBuilder |
callHandler(Class<? extends RestCallHandler> value)
Deprecated.
|
RestContextBuilder |
callHandler(RestCallHandler value)
Deprecated.
|
RestContextBuilder |
callLogger(Class<? extends RestCallLogger> value)
|
RestContextBuilder |
callLogger(RestCallLogger value)
|
RestContextBuilder |
callLoggerConfig(RestCallLoggerConfig value)
|
RestContextBuilder |
child(String path,
Object child)
|
RestContextBuilder |
children(Class<?>... values)
|
RestContextBuilder |
children(Object... values)
|
RestContextBuilder |
classpathResourceFinder(Class<? extends ResourceFinder> value)
|
RestContextBuilder |
classpathResourceFinder(ResourceFinder value)
|
RestContextBuilder |
clientVersionHeader(String value)
|
RestContextBuilder |
config(Config config)
Overwrites the default config file with a custom config file.
|
RestContextBuilder |
consumes(MediaType... values)
|
RestContextBuilder |
consumes(String... values)
|
RestContextBuilder |
consumesReplace(MediaType... values)
|
RestContextBuilder |
consumesReplace(String... values)
|
RestContextBuilder |
context(Class<? extends RestContext> value)
|
RestContextBuilder |
converters(Class<?>... values)
|
RestContextBuilder |
converters(RestConverter... values)
|
protected PropertyStoreBuilder |
createPropertyStore()
Creates a new
PropertyStore object initialized with the properties defined in this config. |
RestContextBuilder |
debug()
|
RestContextBuilder |
debug(Enablement value)
|
RestContextBuilder |
debugOn(String value)
|
RestContextBuilder |
defaultAccept(String value)
Specifies a default
|
RestContextBuilder |
defaultCharset(Charset value)
|
RestContextBuilder |
defaultCharset(String value)
|
RestContextBuilder |
defaultContentType(String value)
Specifies a default
|
RestContextBuilder |
defaultRequestHeader(String name,
Object value)
Deprecated.
|
RestContextBuilder |
defaultRequestHeaders(String... headers)
Deprecated.
|
RestContextBuilder |
defaultResponseHeader(String name,
Object value)
Deprecated.
|
RestContextBuilder |
defaultResponseHeaders(String... headers)
Deprecated.
|
RestContextBuilder |
dictionary(Object... values)
|
RestContextBuilder |
dictionaryOn(Class<?> on,
Class<?>... values)
|
RestContextBuilder |
dontAllowBodyParam()
|
RestContextBuilder |
dontIgnorePropertiesWithoutSetters()
|
RestContextBuilder |
dontIgnoreTransientFields()
|
RestContextBuilder |
dontIgnoreUnknownNullBeanProperties()
|
RestContextBuilder |
dontUseInterfaceProxies()
|
RestContextBuilder |
encoders(Class<?>... values)
|
RestContextBuilder |
encoders(Encoder... values)
|
<T> RestContextBuilder |
example(Class<T> pojoClass,
T o)
|
<T> RestContextBuilder |
exampleJson(Class<T> pojoClass,
String json)
|
RestContextBuilder |
fluentSetters()
|
RestContextBuilder |
fluentSetters(Class<?> on)
|
Config |
getConfig()
Returns the external configuration file for this resource.
|
String |
getInitParameter(String name) |
Enumeration<String> |
getInitParameterNames() |
String |
getPath()
Returns the REST path defined on this builder.
|
RestContextProperties |
getProperties()
Returns the configuration properties for this resource.
|
ServletContext |
getServletContext() |
String |
getServletName() |
VarResolverBuilder |
getVarResolverBuilder()
Creates the variable resolver for this resource.
|
RestContextBuilder |
guards(Class<?>... values)
|
RestContextBuilder |
guards(RestGuard... values)
|
RestContextBuilder |
ignoreInvocationExceptionsOnGetters()
|
RestContextBuilder |
ignoreInvocationExceptionsOnSetters()
|
RestContextBuilder |
ignoreUnknownBeanProperties()
|
RestContextBuilder |
implClass(Class<?> interfaceClass,
Class<?> implClass)
|
RestContextBuilder |
implClasses(Map<Class<?>,Class<?>> values)
|
RestContextBuilder |
infoProvider(Class<? extends RestInfoProvider> value)
|
RestContextBuilder |
infoProvider(RestInfoProvider value)
|
RestContextBuilder |
interfaceClass(Class<?> on,
Class<?> value)
Identifies a class to be used as the interface class for the specified class and all subclasses.
|
RestContextBuilder |
interfaces(Class<?>... value)
Identifies a set of interfaces.
|
RestContextBuilder |
locale(Locale value)
|
RestContextBuilder |
logger(Class<? extends RestLogger> value)
Deprecated.
|
RestContextBuilder |
logger(RestLogger value)
Deprecated.
|
RestContextBuilder |
maxInput(String value)
|
RestContextBuilder |
mediaType(MediaType value)
|
RestContextBuilder |
messages(Class<?> baseClass,
String bundlePath)
|
RestContextBuilder |
messages(String bundlePath)
|
RestContextBuilder |
mimeTypes(String... values)
|
RestContextBuilder |
notBeanClasses(Object... values)
|
RestContextBuilder |
notBeanPackages(Object... values)
|
RestContextBuilder |
paramResolvers(Class<? extends RestMethodParam>... values)
|
RestContextBuilder |
paramResolvers(RestMethodParam... values)
|
RestContextBuilder |
parserListener(Class<? extends ParserListener> value)
|
RestContextBuilder |
parsers(Class<?>... values)
|
RestContextBuilder |
parsers(Object... values)
|
RestContextBuilder |
parsersReplace(Object... values)
|
RestContextBuilder |
partParser(Class<? extends HttpPartParser> value)
|
RestContextBuilder |
partParser(HttpPartParser value)
|
RestContextBuilder |
partSerializer(Class<? extends HttpPartSerializer> value)
|
RestContextBuilder |
partSerializer(HttpPartSerializer value)
|
RestContextBuilder |
path(String value)
|
RestContextBuilder |
prependTo(String name,
Object value)
Adds a free-form value to the beginning of a LIST property.
|
RestContextBuilder |
produces(MediaType... values)
|
RestContextBuilder |
produces(String... values)
|
RestContextBuilder |
producesReplace(MediaType... values)
|
RestContextBuilder |
producesReplace(String... values)
|
RestContextBuilder |
properties(Map<String,Object> values)
|
RestContextBuilder |
property(String name,
Object value)
|
RestContextBuilder |
propertyNamer(Class<?> on,
Class<? extends PropertyNamer> value)
Bean property namer
|
RestContextBuilder |
propertyNamer(Class<? extends PropertyNamer> value)
|
RestContextBuilder |
putAllTo(String name,
Object value)
Adds or overwrites multiple free-form entries in a MAP property.
|
RestContextBuilder |
putTo(String name,
String key,
Object value)
Adds or overwrites a free-form entry in a MAP property.
|
RestContextBuilder |
removeFrom(String name,
Object value)
Removes a free-form value from a SET, LIST, or MAP property.
|
RestContextBuilder |
renderResponseStackTraces()
|
RestContextBuilder |
renderResponseStackTraces(boolean value)
|
RestContextBuilder |
reqAttr(String name,
Object value)
|
RestContextBuilder |
reqAttrs(String... values)
|
RestContextBuilder |
reqHeader(String name,
Object value)
|
RestContextBuilder |
reqHeaders(String... headers)
|
RestContextBuilder |
resHeader(String name,
Object value)
|
RestContextBuilder |
resHeaders(String... headers)
|
RestContextBuilder |
resourceResolver(Class<? extends RestResourceResolver> value)
REST resource resolver.
|
RestContextBuilder |
resourceResolver(RestResourceResolver value)
REST resource resolver.
|
RestContextBuilder |
responseHandlers(Class<?>... values)
|
RestContextBuilder |
responseHandlers(ResponseHandler... values)
|
RestContextBuilder |
roleGuard(String value)
|
RestContextBuilder |
rolesDeclared(String... values)
|
RestContextBuilder |
serializerListener(Class<? extends SerializerListener> value)
|
RestContextBuilder |
serializers(Class<?>... values)
|
RestContextBuilder |
serializers(Object... values)
|
RestContextBuilder |
serializersReplace(Class<?>... values)
|
RestContextBuilder |
serializersReplace(Object... values)
|
RestContextBuilder |
set(Map<String,Object> properties)
Sets multiple free-form configuration properties on this object replacing all previous values.
|
RestContextBuilder |
set(String name,
Object value)
Sets a free-form configuration property on this object.
|
RestContextBuilder |
sortProperties()
|
RestContextBuilder |
sortProperties(Class<?>... on)
Sort bean properties.
|
RestContextBuilder |
staticFileResponseHeader(String name,
String value)
|
RestContextBuilder |
staticFileResponseHeaders(Map<String,String> headers)
|
RestContextBuilder |
staticFileResponseHeaders(String... headers)
|
RestContextBuilder |
staticFileResponseHeadersReplace(Map<String,String> headers)
|
RestContextBuilder |
staticFiles(Class<?> baseClass,
String mappingString)
|
RestContextBuilder |
staticFiles(Class<?> baseClass,
String path,
String location)
|
RestContextBuilder |
staticFiles(StaticFileMapping... values)
|
RestContextBuilder |
staticFiles(String mappingString)
|
RestContextBuilder |
staticFiles(String path,
String location)
|
RestContextBuilder |
stopClass(Class<?> on,
Class<?> value)
Identifies a stop class for the annotated class.
|
RestContextBuilder |
swaps(Object... values)
|
RestContextBuilder |
timeZone(TimeZone value)
|
RestContextBuilder |
typeName(Class<?> on,
String value)
An identifying name for this class.
|
RestContextBuilder |
typePropertyName(Class<?> on,
String value)
|
RestContextBuilder |
typePropertyName(String value)
|
RestContextBuilder |
uriAuthority(String value)
|
RestContextBuilder |
uriContext(String value)
|
RestContextBuilder |
uriRelativity(String value)
|
RestContextBuilder |
uriResolution(String value)
|
RestContextBuilder |
useClasspathResourceCaching(boolean value)
|
RestContextBuilder |
useEnumNames()
|
RestContextBuilder |
useJavaBeanIntrospector()
|
RestContextBuilder |
useStackTraceHashes(boolean value)
Deprecated.
|
RestContextBuilder |
varContextObject(String name,
Object object)
Adds a var context object to this config.
|
RestContextBuilder |
vars(Class<?>... vars)
Adds the specified
Var classes to this config. |
RestContextBuilder |
widgets(Class<? extends Widget>... values)
Deprecated.
|
RestContextBuilder |
widgets(Widget... values)
Deprecated.
|
RestContextBuilder |
widgetsReplace(Class<? extends Widget>... values)
Deprecated.
|
RestContextBuilder |
widgetsReplace(Widget... values)
Deprecated.
|
beanDictionary, beanDictionary, beanDictionaryRemove, beanDictionaryRemove, beanDictionaryReplace, beanDictionaryReplace, beanFilters, beanFiltersRemove, beanFiltersReplace, beanMapPutReturnsOldValue, beansRequireDefaultConstructor, beansRequireSerializable, beansRequireSettersForGetters, beansRequireSomeProperties, debug, excludeProperties, excludeProperties, excludeProperties, fluentSetters, ignoreInvocationExceptionsOnGetters, ignoreInvocationExceptionsOnSetters, ignorePropertiesWithoutSetters, ignoreTransientFields, ignoreUnknownBeanProperties, ignoreUnknownNullBeanProperties, includeProperties, includeProperties, includeProperties, pojoSwaps, pojoSwapsRemove, pojoSwapsReplace, sortProperties, useEnumNames, useInterfaceProxies, useJavaBeanIntrospector
build, getPropertyStore, getPropertyStoreBuilder, peek, peek
public RestContext build()
ContextBuilder
build
in class BeanContextBuilder
public RestContextBuilder vars(Class<?>... vars)
Var
classes to this config.
These variables affect the variable resolver returned by RestRequest.getVarResolverSession()
which is
used to resolve string variables of the form
See RestContext.getVarResolver()
for a list of predefined variables.
vars
- The Var
classes to add to this config.public RestContextBuilder varContextObject(String name, Object object)
Var context objects are read-only objects associated with the variable resolver for vars that require external information.
For example, the ConfigVar
needs access to this resource's Config
through the
ConfigVar.SESSION_config
object that can be specified as either a session object (temporary) or
context object (permanent).
In this case, we call the following code to add it to the context map:
config.addVarContextObject(
name
- The context object key (i.e. the name that the Var class looks for).object
- The context object.public RestContextBuilder config(Config config)
By default, the config file is determined using the @Rest(config)
annotation.
This method allows you to programmatically override it with your own custom config file.
config
- The new config file.protected PropertyStoreBuilder createPropertyStore()
PropertyStore
object initialized with the properties defined in this config.public Config getConfig()
The configuration file location is determined via the @Rest(config)
annotation on the resource.
The config file can be programmatically overridden by adding the following method to your resource:
If a config file is not set up, then an empty config file will be returned that is not backed by any file.
public RestContextProperties getProperties()
The configuration properties are determined via the @Rest(properties)
annotation on the resource.
The configuration properties can be augmented programmatically by adding the following method to your resource:
These properties can be modified during servlet initialization.
However, any modifications made after RestServlet.init(ServletConfig)
has been called will have no effect.
public VarResolverBuilder getVarResolverBuilder()
The variable resolver returned by this method can resolve the following variables:
Note that the variables supported here are only a subset of those returned by
RestRequest.getVarResolverSession()
.
public String getPath()
public RestContextBuilder allowBodyParam(boolean value)
When enabled, the HTTP body content on PUT and POST requests can be passed in as text using the
For example:
?body=(name='John%20Smith',age=45)
value
- The new value for this setting.
public RestContextBuilder dontAllowBodyParam()
When enabled, the HTTP body content on PUT and POST requests can be passed in as text using the
For example:
?body=(name='John%20Smith',age=45)
public RestContextBuilder allowedHeaderParams(String value)
When specified, allows headers such as
For example:
?Accept=text/json&Content-Type=text/json
value
- The new value for this setting.
public RestContextBuilder allowedMethodHeaders(String value)
A comma-delimited list of HTTP method names that are allowed to be passed as values in an
Allows you to override the actual HTTP method with a simulated method.
For example, if an HTTP Client API doesn't support
value
- The new value for this setting.
public RestContextBuilder allowedMethodParams(String value)
When specified, the HTTP method can be overridden by passing in a
For example:
?method=OPTIONS
value
- The new value for this setting.
["HEAD" ,"OPTIONS" ]
.
@Deprecated public RestContextBuilder allowHeaderParams(boolean value)
allowedHeaderParams(String)
When enabled, headers such as
For example:
?Accept=text/json&Content-Type=text/json
value
- The new value for this setting.
@Deprecated public RestContextBuilder callHandler(Class<? extends RestCallHandler> value)
RestContext.REST_context
and override methods.
@Deprecated public RestContextBuilder callHandler(RestCallHandler value)
RestContext.REST_context
and override methods.
public RestContextBuilder callLogger(Class<? extends RestCallLogger> value)
Specifies the logger to use for logging of HTTP requests and responses.
value
- The new value for this setting.
BasicRestCallLogger
.public RestContextBuilder callLogger(RestCallLogger value)
Specifies the logger to use for logging of HTTP requests and responses.
value
- The new value for this setting.
BasicRestCallLogger
.public RestContextBuilder callLoggerConfig(RestCallLoggerConfig value)
Specifies rules on how to handle logging of HTTP requests/responses.
value
- The new value for this setting.
RestCallLoggerConfig.DEFAULT_NOOP
.public RestContextBuilder children(Class<?>... values)
Defines children of this resource.
A REST child resource is simply another servlet that is initialized as part of the parent resource and has a servlet path directly under the parent servlet path.
values
- The values to add to this setting.public RestContextBuilder children(Object... values)
Same as children(Class...)
except input is pre-constructed instances.
values
- The values to add to this setting.public RestContextBuilder child(String path, Object child)
Shortcut for adding a single child to this resource.
This can be used for resources that don't have a @Rest(path)
annotation.
path
- The child path relative to the parent resource URI.child
- The child to add to this resource.public RestContextBuilder classpathResourceFinder(Class<? extends ResourceFinder> value)
Used to retrieve localized files from the classpath.
value
- The new value for this setting.
BasicResourceFinder
.public RestContextBuilder classpathResourceFinder(ResourceFinder value)
Same as classpathResourceFinder(ResourceFinder)
except input is a pre-constructed instance.
value
- The new value for this setting.
BasicResourceFinder
.public RestContextBuilder clientVersionHeader(String value)
Specifies the name of the header used to denote the client version on HTTP requests.
The client version is used to support backwards compatibility for breaking REST interface changes.
Used in conjunction with @RestMethod(clientVersion)
annotation.
value
- The new value for this setting.
public RestContextBuilder context(Class<? extends RestContext> value)
Allows you to extend the RestContext
class to modify how any of the methods are implemented.
The subclass must provide the following:
RestContextBuilder
.
value
- The new value for this setting.public RestContextBuilder converters(Class<?>... values)
Associates one or more converters
with a resource class.
values
- The values to add to this setting.public RestContextBuilder converters(RestConverter... values)
Same as converters(Class...)
except input is pre-constructed instances.
values
- The values to add to this setting.public RestContextBuilder debug(Enablement value)
Enables the following:
value
- The new value for this setting.public RestContextBuilder debugOn(String value)
value
- The new value for this setting.public RestContextBuilder defaultCharset(String value)
The default character encoding for the request and response if not specified on the request.
value
- The new value for this setting.
public RestContextBuilder defaultCharset(Charset value)
Same as defaultCharset(Charset)
but takes in an instance of Charset
.
value
- The new value for this setting.
@Deprecated public RestContextBuilder attrs(String... values) throws RestServletException
reqAttrs(String...)
RestServletException
@Deprecated public RestContextBuilder defaultRequestHeaders(String... headers) throws RestServletException
reqHeaders(String...)
RestServletException
public RestContextBuilder defaultAccept(String value)
value
- The default value of the public RestContextBuilder defaultContentType(String value)
value
- The default value of the @Deprecated public RestContextBuilder attr(String name, Object value)
reqAttr(String, Object)
@Deprecated public RestContextBuilder defaultRequestHeader(String name, Object value)
reqHeader(String,Object)
@Deprecated public RestContextBuilder defaultResponseHeaders(String... headers) throws RestServletException
resHeaders(String...)
RestServletException
@Deprecated public RestContextBuilder defaultResponseHeader(String name, Object value)
resHeader(String, Object)
public RestContextBuilder encoders(Class<?>... values)
These can be used to enable various kinds of compression (e.g.
values
- The values to add to this setting.public RestContextBuilder encoders(Encoder... values)
Same as encoders(Class...)
except input a pre-constructed instances.
values
- The values to add to this setting.public RestContextBuilder guards(Class<?>... values)
Associates one or more RestGuards
with all REST methods defined in this class.
values
- The values to add to this setting.public RestContextBuilder guards(RestGuard... values)
Same as guards(Class...)
except input is pre-constructed instances.
values
- The values to add to this setting.public RestContextBuilder infoProvider(Class<? extends RestInfoProvider> value)
Class used to retrieve title/description/swagger information about a resource.
value
- The new value for this setting.
BasicRestInfoProvider
.public RestContextBuilder infoProvider(RestInfoProvider value)
Same as infoProvider(Class)
except input is a pre-constructed instance.
value
- The new value for this setting.
BasicRestInfoProvider
.@Deprecated public RestContextBuilder logger(Class<? extends RestLogger> value)
callLogger(Class)
Specifies the logger to use for logging.
value
- The new value for this setting.
BasicRestCallLogger
.
@Deprecated public RestContextBuilder logger(RestLogger value)
callLogger(RestCallLogger)
Same as logger(Class)
except input is a pre-constructed instance.
value
- The new value for this setting.
BasicRestLogger
.
public RestContextBuilder maxInput(String value)
Useful for alleviating DoS attacks by throwing an exception when too much input is received instead of resulting in out-of-memory errors which could affect system stability.
value
- The new value for this setting.
public RestContextBuilder messages(Class<?> baseClass, String bundlePath)
baseClass
- The base class that the bundle path is relative to.
bundlePath
- The bundle path relative to the base class.public RestContextBuilder messages(String bundlePath)
Same as messages(Class,String)
except assumes the base class is the resource class itself.
bundlePath
- The bundle path relative to the base class.public RestContextBuilder mimeTypes(String... values)
Defines MIME-type file type mappings.
values
- The values to add to this setting.public RestContextBuilder paramResolvers(Class<? extends RestMethodParam>... values)
By default, the Juneau framework will automatically Java method parameters of various types (e.g.
values
- The values to add to this setting.public RestContextBuilder paramResolvers(RestMethodParam... values)
Same as paramResolvers(Class...)
except input is pre-constructed instances.
values
- The values to add to this setting.public RestContextBuilder parserListener(Class<? extends ParserListener> value)
Specifies the parser listener class to use for listening to non-fatal parsing errors.
value
- The new value for this setting.public RestContextBuilder parsers(Class<?>... values)
Adds class-level parsers to this resource.
values
- The values to add to this setting.public RestContextBuilder parsers(Object... values)
Same as parsers(Class...)
except input is pre-constructed instances.
Parser instances are considered set-in-stone and do NOT inherit properties and transforms defined on the resource class or method.
values
- The values to add to this setting.public RestContextBuilder parsersReplace(Object... values)
Same as parsers(Class...)
except allows you to overwrite the previous value.
values
- The values to add to this setting.public RestContextBuilder partParser(Class<? extends HttpPartParser> value)
Specifies the HttpPartParser
to use for parsing headers, query/form parameters, and URI parts.
value
- The new value for this setting.
OpenApiParser
.public RestContextBuilder partParser(HttpPartParser value)
Same as partParser(Class)
except input is a pre-constructed instance.
value
- The new value for this setting.
OpenApiParser
.public RestContextBuilder partSerializer(Class<? extends HttpPartSerializer> value)
Specifies the HttpPartSerializer
to use for serializing headers, query/form parameters, and URI parts.
value
- The new value for this setting.
OpenApiSerializer
.public RestContextBuilder partSerializer(HttpPartSerializer value)
Same as partSerializer(Class)
except input is a pre-constructed instance.
value
- The new value for this setting.
OpenApiSerializer
.public RestContextBuilder path(String value)
Identifies the URL subpath relative to the parent resource.
value
- The new value for this setting.public RestContextBuilder renderResponseStackTraces(boolean value)
Render stack traces in HTTP response bodies when errors occur.
value
- The new value for this setting.
public RestContextBuilder renderResponseStackTraces()
Shortcut for calling renderResponseStackTraces(
.
public RestContextBuilder reqAttr(String name, Object value)
Same as reqAttrs(String...)
but adds a single attribute name/value pair.
name
- The HTTP header name.value
- The HTTP header value.public RestContextBuilder reqAttrs(String... values) throws RestServletException
Specifies default values for request attributes if they're not already set on the request.
values
- The attributes in the format RestServletException
- If malformed header is found.public RestContextBuilder reqHeader(String name, Object value)
Same as reqHeaders(String...)
but adds a single header name/value pair.
name
- The HTTP header name.value
- The HTTP header value.public RestContextBuilder reqHeaders(String... headers) throws RestServletException
Specifies default values for request headers if they're not passed in through the request.
headers
- The headers in the format RestServletException
- If malformed header is found.public RestContextBuilder resHeaders(String... headers) throws RestServletException
Specifies default values for response headers if they're not set after the Java REST method is called.
headers
- The headers in the format RestServletException
- If malformed header is found.public RestContextBuilder resHeader(String name, Object value)
Same as resHeaders(String...)
but adds a single header name/value pair.
name
- The HTTP header name.value
- The HTTP header value.public RestContextBuilder resourceResolver(Class<? extends RestResourceResolver> value)
The resolver used for resolving child resources.
Can be used to provide customized resolution of REST resource class instances (e.g. resources retrieve from Spring).
value
- The new value for this setting.
BasicRestResourceResolver
.public RestContextBuilder resourceResolver(RestResourceResolver value)
Same as resourceResolver(Class)
except input is a pre-constructed instance.
value
- The new value for this setting.
BasicRestResourceResolver
.public RestContextBuilder responseHandlers(Class<?>... values)
Specifies a list of ResponseHandler
classes that know how to convert POJOs returned by REST methods or
set via RestResponse.setOutput(Object)
into appropriate HTTP responses.
values
- The values to add to this setting.public RestContextBuilder responseHandlers(ResponseHandler... values)
Same as responseHandlers(Class...)
except input is pre-constructed instances.
values
- The values to add to this setting.public RestContextBuilder rolesDeclared(String... values)
A comma-delimited list of all possible user roles.
Used in conjunction with roleGuard(String)
is used with patterns.
values
- The values to add to this setting.public RestContextBuilder roleGuard(String value)
An expression defining if a user with the specified roles are allowed to access methods on this class.
Rest.rolesDeclared()
or RestContext.REST_rolesDeclared
.
value
- The values to add to this setting.public RestContextBuilder serializerListener(Class<? extends SerializerListener> value)
Specifies the serializer listener class to use for listening to non-fatal serialization errors.
value
- The new value for this setting.public RestContextBuilder serializers(Class<?>... values)
Adds class-level serializers to this resource.
values
- The values to add to this setting.public RestContextBuilder serializersReplace(Class<?>... values)
Same as serializers(Class[])
but replaces any existing values.
values
- The values to set on this setting.public RestContextBuilder serializers(Object... values)
Same as serializers(Class...)
except input is pre-constructed instances.
Serializer instances are considered set-in-stone and do NOT inherit properties and transforms defined on the resource class or method.
values
- The values to add to this setting.public RestContextBuilder serializersReplace(Object... values)
Same as serializers(Class...)
except allows you to overwrite the previous value.
values
- The values to add to this setting.public RestContextBuilder staticFileResponseHeaders(Map<String,String> headers)
Used to customize the headers on responses returned for statically-served files.
headers
- The headers to add to this list.
{'Cache-Control' : 'max-age=86400, public }
.public RestContextBuilder staticFileResponseHeadersReplace(Map<String,String> headers)
Same as staticFileResponseHeaders(Map)
but replaces any previous values.
headers
- The headers to set on this list.
{'Cache-Control' : 'max-age=86400, public }
.public RestContextBuilder staticFileResponseHeaders(String... headers) throws RestServletException
Same as staticFileResponseHeaders(Map)
with append=
headers
- The headers in the format RestServletException
- If malformed header is found.public RestContextBuilder staticFileResponseHeader(String name, String value)
Same as staticFileResponseHeaders(String...)
except header is broken into name/value pair.
name
- The HTTP header name.value
- The HTTP header value.public RestContextBuilder staticFiles(StaticFileMapping... values)
Used to define paths and locations of statically-served files such as images or HTML documents.
values
- The values to append to this setting.public RestContextBuilder staticFiles(String mappingString) throws ParseException
Same as staticFiles(StaticFileMapping...)
except input is in the form of a mapping string.
Mapping string must be one of these formats:
mappingString
- The static file mapping string.ParseException
- If mapping string is malformed.public RestContextBuilder staticFiles(Class<?> baseClass, String mappingString) throws ParseException
Same as staticFiles(String)
except overrides the base class for retrieving the resource.
Mapping string must be one of these formats:
baseClass
- Overrides the default class to use for retrieving the classpath resource.
mappingString
- The static file mapping string.ParseException
- If mapping string is malformed.public RestContextBuilder staticFiles(String path, String location)
Same as staticFiles(String)
except path and location are already split values.
path
- The mapped URI path.
location
- The location relative to the resource class.
public RestContextBuilder staticFiles(Class<?> baseClass, String path, String location)
Same as staticFiles(String,String)
except overrides the base class for retrieving the resource.
baseClass
- Overrides the default class to use for retrieving the classpath resource.
path
- The mapped URI path.
location
- The location relative to the resource class.
public RestContextBuilder produces(String... values)
Overrides the media types inferred from the serializers that identify what media types can be produced by the resource.
values
- The values to add to this setting.public RestContextBuilder producesReplace(String... values)
Same as produces(String...)
but replaces any previous values.
values
- The values to set on this setting.public RestContextBuilder produces(MediaType... values)
Same as produces(String...)
except input is MediaType
instances.
values
- The values to add to this setting.public RestContextBuilder producesReplace(MediaType... values)
Same as produces(MediaType...)
but replaces any previous values.
values
- The values to set on this setting.public RestContextBuilder consumes(String... values)
Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource.
values
- The values to add to this setting.public RestContextBuilder consumesReplace(String... values)
Same as consumes(String...)
but replaces any existing values.
values
- The values to set on this setting.public RestContextBuilder consumes(MediaType... values)
Same as consumes(String...)
except input is MediaType
instances.
values
- The values to add to this setting.public RestContextBuilder consumesReplace(MediaType... values)
Same as consumes(MediaType...)
except replaces any existing values.
values
- The values to set on this setting.public RestContextBuilder properties(Map<String,Object> values)
Shortcut to add properties to the bean contexts of all serializers and parsers on all methods in the class.
Any of the properties defined on RestContext
or any of the serializers and parsers can be specified.
Property values will be converted to the appropriate type.
values
- The values to set on this setting.public RestContextBuilder property(String name, Object value)
Shortcut to add properties to the bean contexts of all serializers and parsers on all methods in the class.
Any of the properties defined on RestContext
or any of the serializers and parsers can be specified.
Property values will be converted to the appropriate type.
name
- The key to add to the properties.value
- The value to add to the properties.public RestContextBuilder uriAuthority(String value)
Overrides the authority path value for this resource and any child resources.
This setting is useful if you want to resolve relative URIs to absolute paths and want to explicitly specify the hostname/port.
value
- The new value for this setting.public RestContextBuilder uriContext(String value)
Overrides the context path value for this resource and any child resources.
This setting is useful if you want to use
value
- The new value for this setting.public RestContextBuilder uriRelativity(String value)
Specifies how relative URIs should be interpreted by serializers.
See UriResolution
for possible values.
value
- The new value for this setting.public RestContextBuilder uriResolution(String value)
Specifies how relative URIs should be interpreted by serializers.
See UriResolution
for possible values.
value
- The new value for this setting.public RestContextBuilder useClasspathResourceCaching(boolean value)
When enabled, resources retrieved via RestContext.getClasspathResource(String, Locale)
(and related
methods) will be cached in memory to speed subsequent lookups.
value
- The new value for this setting.
@Deprecated public RestContextBuilder useStackTraceHashes(boolean value)
callLoggerConfig(RestCallLoggerConfig)
When enabled, the number of times an exception has occurred will be determined based on stack trace hashsums,
made available through the RestException.getOccurrence()
method.
value
- The new value for this setting.
@Deprecated public RestContextBuilder widgets(Class<? extends Widget>... values)
HtmlDocSerializerBuilder.widgets(Class[])
Defines widgets that can be used in conjunction with string variables of the form
values
- The values to add to this setting.@Deprecated public RestContextBuilder widgetsReplace(Class<? extends Widget>... values)
HtmlDocSerializerBuilder.widgetsReplace(Class[])
Same as widgets(Class...)
but replaces any previous values.
values
- The values to set on this setting.@Deprecated public RestContextBuilder widgets(Widget... values)
HtmlDocSerializerBuilder.widgets(HtmlWidget[])
Same as widgets(Class...)
except input is pre-constructed instances.
values
- The values to add to this setting.@Deprecated public RestContextBuilder widgetsReplace(Widget... values)
HtmlDocSerializerBuilder.widgetsReplace(HtmlWidget[])
Same as widgets(Widget...)
except allows you to overwrite the previous value.
values
- The values to add to this setting.public RestContextBuilder set(String name, Object value)
ContextBuilder
Provides the ability to specify configuration property values in a generic fashion.
Property names must have the following format that identify their datatype...
...where the parts consist of the following...
For example,
Property values get 'normalized' when they get set.
For example, calling PropertyStore
class to be comparable
and useful in determining whether a cached instance of a context object can be returned.
As a general rule, builders don't typically have "unsetter" methods. For example, once you've set strict
mode on the
set
in class BeanContextBuilder
name
- The property name.value
- The property value.
public RestContextBuilder set(Map<String,Object> properties)
ContextBuilder
Identical in function to ContextBuilder.set(String, Object)
but allows you to specify multiple values at once.
set
in class BeanContextBuilder
properties
- The properties to set on this class.
public RestContextBuilder add(Map<String,Object> properties)
ContextBuilder
Identical in function to ContextBuilder.set(String, Object)
but allows you to specify multiple values at once.
add
in class BeanContextBuilder
properties
- The properties to set on this class.
public RestContextBuilder addTo(String name, Object value)
ContextBuilder
SET properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_notBeanClasses
property which has the value
addTo
in class BeanContextBuilder
name
- The property name.value
- The new value to add to the SET property.
public RestContextBuilder appendTo(String name, Object value)
ContextBuilder
LIST properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_swaps
property which has the value
appendTo
in class BeanContextBuilder
name
- The property name.value
- The new value to add to the LIST property.
public RestContextBuilder apply(PropertyStore copyFrom)
ContextBuilder
apply
in class BeanContextBuilder
copyFrom
- The property store whose settings are being copied.public RestContextBuilder applyAnnotations(Class<?>... fromClasses)
ContextBuilder
Any annotations found that themselves are annotated with PropertyStoreApply
will be resolved and
applied as properties to this builder. These annotations include:
BeanConfig
CsvConfig
HtmlConfig
HtmlDocConfig
JsoConfig
JsonConfig
JsonSchemaConfig
MsgPackConfig
OpenApiConfig
ParserConfig
PlainTextConfig
SerializerConfig
SoapXmlConfig
UonConfig
UrlEncodingConfig
XmlConfig
Annotations on classes are appended in the following order:
The default var resolver VarResolver.DEFAULT
is used to resolve any variables in annotation field values.
applyAnnotations
in class BeanContextBuilder
fromClasses
- The classes on which the annotations are defined.public RestContextBuilder applyAnnotations(Method... fromMethods)
ContextBuilder
Any annotations found that themselves are annotated with PropertyStoreApply
will be resolved and
applied as properties to this builder. These annotations include:
BeanConfig
CsvConfig
HtmlConfig
HtmlDocConfig
JsoConfig
JsonConfig
JsonSchemaConfig
MsgPackConfig
OpenApiConfig
ParserConfig
PlainTextConfig
SerializerConfig
SoapXmlConfig
UonConfig
UrlEncodingConfig
XmlConfig
Annotations on methods are appended in the following order:
The default var resolver VarResolver.DEFAULT
is used to resolve any variables in annotation field values.
applyAnnotations
in class BeanContextBuilder
fromMethods
- The methods on which the annotations are defined.public RestContextBuilder applyAnnotations(AnnotationList al, VarResolverSession r)
ContextBuilder
The AnnotationList
object is an ordered list of annotations and the classes/methods/packages they were found on.
applyAnnotations
in class BeanContextBuilder
al
- The list of all annotations annotated with PropertyStoreApply
.r
- The string resolver for resolving variables in annotation values.public RestContextBuilder debug()
ContextBuilder
Enables the following additional information during serialization:
BeanTraverseContext.BEANTRAVERSE_detectRecursions
.
Enables the following additional information during parsing:
debug
in class BeanContextBuilder
public RestContextBuilder locale(Locale value)
ContextBuilder
Specifies the default locale for serializer and parser sessions when not specified via SessionArgs.locale(Locale)
.
Typically used for POJO swaps that need to deal with locales such as swaps that convert PojoSwap.swap(BeanSession, Object)
and
PojoSwap.unswap(BeanSession, Object, ClassMeta, String)
methods.
locale
in class BeanContextBuilder
value
- The new value for this property.public RestContextBuilder mediaType(MediaType value)
ContextBuilder
Specifies the default media type for serializer and parser sessions when not specified via SessionArgs.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
mediaType
in class BeanContextBuilder
value
- The new value for this property.public RestContextBuilder prependTo(String name, Object value)
ContextBuilder
LIST properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_swaps
property which has the value
prependTo
in class BeanContextBuilder
name
- The property name.value
- The new value to add to the LIST property.
public RestContextBuilder putAllTo(String name, Object value)
ContextBuilder
MAP properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_implClasses
property which has the value
putAllTo
in class BeanContextBuilder
name
- The property name.value
- Either a JSON Object string or a Map
whose valid value types depend on the property type:
public RestContextBuilder putTo(String name, String key, Object value)
ContextBuilder
MAP properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_implClasses
property which has the value
putTo
in class BeanContextBuilder
name
- The property name.key
- The property value map key.value
- The property value map value.
public RestContextBuilder removeFrom(String name, Object value)
ContextBuilder
removeFrom
in class BeanContextBuilder
name
- The property name.value
- The property value in the SET/LIST/MAP property.public RestContextBuilder timeZone(TimeZone value)
ContextBuilder
Specifies the default time zone for serializer and parser sessions when not specified via SessionArgs.timeZone(TimeZone)
.
Typically used for POJO swaps that need to deal with timezones such as swaps that convert PojoSwap.swap(BeanSession, Object)
and
PojoSwap.unswap(BeanSession, Object, ClassMeta, String)
methods.
timeZone
in class BeanContextBuilder
value
- The new value for this property.public RestContextBuilder annotations(Annotation... values)
BeanContextBuilder
Defines 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
The following example shows the equivalent methods for applying the @Bean
annotation:
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:
The following is the list of concrete annotations provided that can be constructed and passed into the builder class:
BeanAnnotation
BeancAnnotation
BeanIgnoreAnnotation
BeanpAnnotation
ExampleAnnotation
NamePropertyAnnotation
ParentPropertyAnnotation
SwapAnnotation
UriAnnotation
CsvAnnotation
HtmlAnnotation
JsoAnnotation
JsonAnnotation
SchemaAnnotation
MsgPackAnnotation
OpenApiAnnotation
PlainTextAnnotation
SoapXmlAnnotation
UonAnnotation
UrlEncodingAnnotation
XmlAnnotation
The syntax for the
annotations
in class BeanContextBuilder
values
- The values to add to this property.public RestContextBuilder beanClassVisibility(Visibility value)
BeanContextBuilder
Classes are not considered beans unless they meet the minimum visibility requirements.
For example, if the visibility is
@Bean
annotation can be used on a non-public bean class to override this setting.
@BeanIgnore
annotation can also be used on a public bean class to ignore it as a bean.
beanClassVisibility
in class BeanContextBuilder
value
- The new value for this property.
Visibility.PUBLIC
.public RestContextBuilder beanConstructorVisibility(Visibility value)
BeanContextBuilder
Only look for constructors with the specified minimum visibility.
This setting affects the logic for finding no-arg constructors for bean. Normally, only
@Beanc
annotation can also be used to expose a non-public constructor.
@BeanIgnore
annotation can also be used on a public bean constructor to ignore it.
beanConstructorVisibility
in class BeanContextBuilder
value
- The new value for this property.
Visibility.PUBLIC
.public RestContextBuilder beanFieldVisibility(Visibility value)
BeanContextBuilder
Only look for bean fields with the specified minimum visibility.
This affects which fields on a bean class are considered bean properties. Normally only
Bean fields can be ignored as properties entirely by setting the value to Visibility.NONE
@Beanp
annotation can also be used to expose a non-public field.
@BeanIgnore
annotation can also be used on a public bean field to ignore it as a bean property.
beanFieldVisibility
in class BeanContextBuilder
value
- The new value for this property.
Visibility.PUBLIC
.public RestContextBuilder beanInterceptor(Class<?> on, Class<? extends BeanInterceptor<?>> value)
BeanContextBuilder
Bean interceptors can be used to intercept calls to getters and setters and alter their values in transit.
beanInterceptor
in class BeanContextBuilder
on
- The bean that the filter applies to.value
- The new value for this property.public RestContextBuilder beanMapPutReturnsOldValue()
BeanContextBuilder
When enabled, then the BeanMap.put()
method will return old property
values. Otherwise, it returns
Disabled by default because it introduces a slight performance penalty during serialization.
beanMapPutReturnsOldValue
in class BeanContextBuilder
public RestContextBuilder beanMethodVisibility(Visibility value)
BeanContextBuilder
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
@Beanp
annotation can also be used to expose a non-public method.
@BeanIgnore
annotation can also be used on a public bean getter/setter to ignore it as a bean property.
beanMethodVisibility
in class BeanContextBuilder
value
- The new value for this property.
Visibility.PUBLIC
public RestContextBuilder beansDontRequireSomeProperties()
BeanContextBuilder
When enabled, then a Java class must contain at least 1 property to be considered a bean.
Otherwise, the bean will be serialized as a string using the Object.toString()
method.
The @Bean
annotation can be used on a class to override this setting when
@Bean
annotation can be used on the class to force it to be recognized as a bean class
even if it has no properties.
beansDontRequireSomeProperties
in class BeanContextBuilder
public RestContextBuilder beansRequireDefaultConstructor()
BeanContextBuilder
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.
@Bean
annotation can be used on a bean class to override this setting.
@BeanIgnore
annotation can also be used on a class to ignore it as a bean.
beansRequireDefaultConstructor
in class BeanContextBuilder
public RestContextBuilder beansRequireSerializable()
BeanContextBuilder
When enabled, a Java class must implement the Serializable
interface to be considered a bean.
Otherwise, the bean will be serialized as a string using the Object.toString()
method.
@Bean
annotation can be used on a bean class to override this setting.
@BeanIgnore
annotation can also be used on a class to ignore it as a bean.
beansRequireSerializable
in class BeanContextBuilder
public RestContextBuilder beansRequireSettersForGetters()
BeanContextBuilder
When enabled, ignore read-only properties (properties with getters but not setters).
@Beanp
annotation can be used on the getter to override this setting.
@BeanIgnore
annotation can also be used on getters to ignore them as bean properties.
beansRequireSettersForGetters
in class BeanContextBuilder
public RestContextBuilder bpi(Map<String,Object> values)
BeanContextBuilder
Specifies the set and order of names of properties associated with bean classes.
For example, BeanContextBuilder.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.
This method is functionally equivalent to the following code for each entry:
builder.annotations(
Bean.bpi()
- On an annotation on the bean class itself.
BeanConfig.bpi()
- On a bean config annotation (see BeanContextBuilder.annotations(Annotation...)
).
bpi
in class BeanContextBuilder
values
- The values to add to this builder.
public RestContextBuilder bpi(Class<?> beanClass, String properties)
BeanContextBuilder
Specifies the set and order of names of properties associated with the bean class.
For example, BeanContextBuilder.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.
This method is functionally equivalent to the following code:
builder.annotations(
Bean.bpi()
- On an annotation on the bean class itself.
BeanConfig.bpi()
- On a bean config annotation (see BeanContextBuilder.annotations(Annotation...)
).
bpi
in class BeanContextBuilder
beanClass
- The bean class.properties
- Comma-delimited list of property names.public RestContextBuilder bpi(String beanClassName, String properties)
BeanContextBuilder
Specifies the set and order of names of properties associated with the bean class.
For example, BeanContextBuilder.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.
This method is functionally equivalent to the following code:
builder.annotations(
Bean.bpi()
- On an annotation on the bean class itself.
BeanConfig.bpi()
- On a bean config annotation (see BeanContextBuilder.annotations(Annotation...)
).
bpi
in class BeanContextBuilder
beanClassName
- The bean class name.
properties
- Comma-delimited list of property names.public RestContextBuilder bpro(Map<String,Object> values)
BeanContextBuilder
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
This method is functionally equivalent to the following code for each entry:
builder.annotations(
bpro
in class BeanContextBuilder
values
- The values to add to this builder.
public RestContextBuilder bpro(Class<?> beanClass, String properties)
BeanContextBuilder
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
This method is functionally equivalent to the following code:
builder.annotations(
bpro
in class BeanContextBuilder
beanClass
- The bean class.properties
- Comma-delimited list of property names.public RestContextBuilder bpro(String beanClassName, String properties)
BeanContextBuilder
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
This method is functionally equivalent to the following code:
builder.annotations(
bpro
in class BeanContextBuilder
beanClassName
- The bean class name.
properties
- Comma-delimited list of property names.public RestContextBuilder bpwo(Map<String,Object> values)
BeanContextBuilder
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
This method is functionally equivalent to the following code for each entry:
builder.annotations(
bpwo
in class BeanContextBuilder
values
- The values to add to this builder.
public RestContextBuilder bpwo(Class<?> beanClass, String properties)
BeanContextBuilder
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
This method is functionally equivalent to the following code:
builder.annotations(
bpwo
in class BeanContextBuilder
beanClass
- The bean class.properties
- Comma-delimited list of property names.public RestContextBuilder bpwo(String beanClassName, String properties)
BeanContextBuilder
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
This method is functionally equivalent to the following code:
builder.annotations(
bpwo
in class BeanContextBuilder
beanClassName
- The bean class name.
properties
- Comma-delimited list of property names.public RestContextBuilder bpx(Map<String,Object> values)
BeanContextBuilder
Specifies to exclude the specified list of properties for the specified bean classes.
Same as BeanContextBuilder.bpi(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.
This method is functionally equivalent to the following code for each entry:
builder.annotations(
bpx
in class BeanContextBuilder
values
- The values to add to this builder.
public RestContextBuilder bpx(Class<?> beanClass, String properties)
BeanContextBuilder
Specifies to exclude the specified list of properties for the specified bean class.
Same as BeanContextBuilder.bpi(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.
This method is functionally equivalent to the following code:
builder.annotations(
bpx
in class BeanContextBuilder
beanClass
- The bean class.properties
- Comma-delimited list of property names.public RestContextBuilder bpx(String beanClassName, String properties)
BeanContextBuilder
Specifies to exclude the specified list of properties for the specified bean class.
Same as BeanContextBuilder.bpx(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.
This method is functionally equivalent to the following code:
builder.annotations(
bpx
in class BeanContextBuilder
beanClassName
- The bean class name.
properties
- Comma-delimited list of property names.public RestContextBuilder dictionary(Object... values)
BeanContextBuilder
The list of classes that make up the bean dictionary in this bean context.
A dictionary is a name/class mapping used to find class types during parsing when they cannot be inferred
through reflection. The names are defined through the @Bean(typeName)
annotation defined
on the bean class. For example, if a class
This setting tells the parsers which classes to look for when resolving
Values can consist of any of the following types:
@Bean(typeName)
.
BeanDictionaryList
containing a collection of bean classes with type name annotations.
BeanDictionaryMap
containing a mapping of type names to classes without type name annotations.
Another option is to use the Bean.dictionary()
annotation on the POJO class itself:
A typical usage is to allow for HTML documents to be parsed back into HTML beans:
dictionary
in class BeanContextBuilder
values
- The values to add to this property.public RestContextBuilder dictionaryOn(Class<?> on, Class<?>... values)
BeanContextBuilder
This is identical to BeanContextBuilder.dictionary(Object...)
, but specifies a dictionary within the context of
a single class as opposed to globally.
This is functionally equivalent to the Bean.dictionary()
annotation.
dictionaryOn
in class BeanContextBuilder
on
- The class that the dictionary values apply to.values
- The new values for this property.public RestContextBuilder dontIgnorePropertiesWithoutSetters()
BeanContextBuilder
When enabled, trying to set a value on a bean property without a setter will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
@BeanIgnore
annotation can also be used on getters and fields to ignore them.
dontIgnorePropertiesWithoutSetters
in class BeanContextBuilder
public RestContextBuilder dontIgnoreTransientFields()
BeanContextBuilder
When enabled, methods and fields marked as
@Beanp
annotation can also be used on transient fields to keep them from being ignored.
dontIgnoreTransientFields
in class BeanContextBuilder
public RestContextBuilder dontIgnoreUnknownNullBeanProperties()
BeanContextBuilder
When enabled, trying to set a BeanRuntimeException
is thrown.
dontIgnoreUnknownNullBeanProperties
in class BeanContextBuilder
public RestContextBuilder dontUseInterfaceProxies()
BeanContextBuilder
When enabled, interfaces will be instantiated as proxy classes through the use of an
InvocationHandler
if there is no other way of instantiating them.
Otherwise, throws a BeanRuntimeException
.
dontUseInterfaceProxies
in class BeanContextBuilder
public <T> RestContextBuilder example(Class<T> pojoClass, T o)
BeanContextBuilder
Specifies an example of the specified class.
Examples are used in cases such as POJO examples in Swagger documents.
Setting applies to specified class and all subclasses.
POJO examples can also be defined on classes via the following:
@Example
.
@Example
with zero arguments or one BeanSession
argument.
BeanSession
argument.
example
in class BeanContextBuilder
pojoClass
- The POJO class.o
- An instance of the POJO class used for examples.public <T> RestContextBuilder exampleJson(Class<T> pojoClass, String json)
BeanContextBuilder
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.
POJO examples can also be defined on classes via the following:
@Example
.
@Example
with zero arguments or one BeanSession
argument.
BeanSession
argument.
exampleJson
in class BeanContextBuilder
T
- The POJO class type.pojoClass
- The POJO class.json
- The simple JSON representation of the example.public RestContextBuilder fluentSetters()
BeanContextBuilder
When enabled, fluent setters are detected on beans during parsing.
Fluent setters must have the following attributes:
@Beanp
annotation can also be used on methods to individually identify them as fluent setters.
@Bean.fluentSetters()
annotation can also be used on classes to specify to look for fluent setters.
fluentSetters
in class BeanContextBuilder
public RestContextBuilder fluentSetters(Class<?> on)
BeanContextBuilder
Identical to BeanContextBuilder.fluentSetters()
but enables it on a specific class only.
Bean.fluentSetters()
annotation.
fluentSetters
in class BeanContextBuilder
on
- The class that this applies to.public RestContextBuilder ignoreInvocationExceptionsOnGetters()
BeanContextBuilder
When enabled, errors thrown when calling bean getter methods will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
ignoreInvocationExceptionsOnGetters
in class BeanContextBuilder
public RestContextBuilder ignoreInvocationExceptionsOnSetters()
BeanContextBuilder
When enabled, errors thrown when calling bean setter methods will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
ignoreInvocationExceptionsOnSetters
in class BeanContextBuilder
public RestContextBuilder ignoreUnknownBeanProperties()
BeanContextBuilder
When enabled, trying to set a value on a non-existent bean property will silently be ignored.
Otherwise, a BeanRuntimeException
is thrown.
ignoreUnknownBeanProperties
in class BeanContextBuilder
public RestContextBuilder implClass(Class<?> interfaceClass, Class<?> implClass)
BeanContextBuilder
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).
implClass
in class BeanContextBuilder
interfaceClass
- The interface class.implClass
- The implementation class.public RestContextBuilder implClasses(Map<Class<?>,Class<?>> values)
BeanContextBuilder
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).
implClasses
in class BeanContextBuilder
values
- The new value for this property.public RestContextBuilder interfaceClass(Class<?> on, Class<?> value)
BeanContextBuilder
When specified, only the list of properties defined on the interface class will be used during serialization. Additional properties on subclasses will be ignored.
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.
@Bean(interfaceClass)
annotation is the equivalent annotation-based solution.
interfaceClass
in class BeanContextBuilder
on
- The class that the interface class applies to.value
- The new value for this property.public RestContextBuilder interfaces(Class<?>... value)
BeanContextBuilder
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.
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.
@Bean(interfaceClass)
annotation is the equivalent annotation-based solution.
interfaces
in class BeanContextBuilder
value
- The new value for this property.public RestContextBuilder notBeanClasses(Object... values)
BeanContextBuilder
List of classes that should not be treated as beans even if they appear to be bean-like.
Not-bean classes are converted to
Values can consist of any of the following types:
@BeanIgnore
annotation can also be used on classes to prevent them from being recognized as beans.
notBeanClasses
in class BeanContextBuilder
values
- The values to add to this property.
public RestContextBuilder notBeanPackages(Object... values)
BeanContextBuilder
Used as a convenient way of defining the BeanContextBuilder.notBeanClasses(Object...)
property for entire packages.
Any classes within these packages will be serialized to strings using Object.toString()
.
Note that you can specify suffix patterns to include all subpackages.
Values can consist of any of the following types:
notBeanPackages
in class BeanContextBuilder
values
- The values to add to this property.
Package
objects.
public RestContextBuilder propertyNamer(Class<? extends PropertyNamer> value)
BeanContextBuilder
The class to use for calculating bean property names.
Predefined classes:
PropertyNamerDefault
- Default.
PropertyNamerDLC
- Dashed-lower-case names.
PropertyNamerULC
- Dashed-upper-case names.
propertyNamer
in class BeanContextBuilder
value
- The new value for this setting.
PropertyNamerDefault
.public RestContextBuilder propertyNamer(Class<?> on, Class<? extends PropertyNamer> value)
BeanContextBuilder
Same as BeanContextBuilder.propertyNamer(Class)
but allows you to specify a namer for a specific class.
propertyNamer
in class BeanContextBuilder
on
- The class that the namer applies to.value
- The new value for this setting.
PropertyNamerDefault
.public RestContextBuilder sortProperties()
BeanContextBuilder
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 property is disabled by default so that IBM JVM users don't have to use @Bean
annotations
to force bean properties to be in a particular order and can just alter the order of the fields/methods
in the Java file.
@Bean.sort()
annotation can also be used to sort properties on just a single class.
sortProperties
in class BeanContextBuilder
public RestContextBuilder sortProperties(Class<?>... on)
BeanContextBuilder
Same as BeanContextBuilder.sortProperties()
but allows you to specify individual bean classes instead of globally.
sortProperties
in class BeanContextBuilder
on
- The bean classes to sort properties on.public RestContextBuilder stopClass(Class<?> on, Class<?> value)
BeanContextBuilder
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
stopClass
in class BeanContextBuilder
on
- The class on which the stop class is being applied.value
- The new value for this property.public RestContextBuilder swaps(Object... values)
BeanContextBuilder
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
Multiple swaps can be associated with a single class.
When multiple swaps are applicable to the same class, the media type pattern defined by
PojoSwap.forMediaTypes()
or @Swap(mediaTypes)
are used to come up with the best match.
Values can consist of any of the following types:
PojoSwap
.
PojoSwap
.
SurrogateSwap
.
swaps
in class BeanContextBuilder
values
- The values to add to this property.
PojoSwap
.
SurrogateSwap
.
public RestContextBuilder typeName(Class<?> on, String value)
BeanContextBuilder
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
It is also used to specify element names in XML.
Bean(typeName)
annotation.
typeName
in class BeanContextBuilder
on
- The class the type name is being defined on.value
- The new value for this property.public RestContextBuilder typePropertyName(String value)
BeanContextBuilder
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.
typePropertyName
in class BeanContextBuilder
value
- The new value for this property.
public RestContextBuilder typePropertyName(Class<?> on, String value)
BeanContextBuilder
Same as BeanContextBuilder.typePropertyName(String)
except targets a specific bean class instead of globally.
typePropertyName
in class BeanContextBuilder
on
- The class the type property name applies to.value
- The new value for this property.
public RestContextBuilder useEnumNames()
BeanContextBuilder
When enabled, enums are always serialized by name, not using Object.toString()
.
useEnumNames
in class BeanContextBuilder
public RestContextBuilder useJavaBeanIntrospector()
BeanContextBuilder
Using the built-in Java bean introspector will not pick up fields or non-standard getters/setters.
Most @Bean
annotations will be ignored.
useJavaBeanIntrospector
in class BeanContextBuilder
public String getInitParameter(String name)
getInitParameter
in interface ServletConfig
public Enumeration<String> getInitParameterNames()
getInitParameterNames
in interface ServletConfig
public ServletContext getServletContext()
getServletContext
in interface ServletConfig
public String getServletName()
getServletName
in interface ServletConfig
Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.