Class RestOpContext.Builder

java.lang.Object
org.apache.juneau.Context.Builder
org.apache.juneau.rest.RestOpContext.Builder
Enclosing class:
RestOpContext

public static final class RestOpContext.Builder extends Context.Builder
Builder class.
  • Method Details

    • copy

      Description copied from class: Context.Builder
      Copy creator.
      Specified by:
      copy in class Context.Builder
      Returns:
      A new mutable copy of this builder.
    • build

      public RestOpContext build()
      Description copied from class: Context.Builder
      Build the object.
      Overrides:
      build in class Context.Builder
      Returns:
      The built object.
    • getDefaultImplClass

      protected Class<? extends RestOpContext> getDefaultImplClass()
      Specifies the default implementation class if not specified via type(Class).
      Returns:
      The default implementation class if not specified via type(Class).
    • resource

      public Supplier<?> resource()
      Returns the REST servlet/bean instance that this context is defined against.
      Returns:
      The REST servlet/bean instance that this context is defined against.
    • defaultClasses

      Returns the default classes list.

      This defines the implementation classes for a variety of bean types.

      Default classes are inherited from the parent REST object. Typically used on the top-level RestContext.Builder to affect class types for that REST object and all children.

      Modifying the default class list on this builder does not affect the default class list on the parent builder, but changes made here are inherited by child builders.

      Returns:
      The default classes list for this builder.
    • beanStore

      public BeanStore beanStore()
      Returns access to the bean store being used by this builder.

      Can be used to add more beans to the bean store.

      Returns:
      The bean store being used by this builder.
    • beanStore

      protected RestOpContext.Builder beanStore(BeanStore beanStore)
      Specifies a BeanStore to use when resolving constructor arguments.
      Parameters:
      beanStore - The bean store to use for resolving constructor arguments.
      Returns:
      This object.
    • beanStore

      public <T> RestOpContext.Builder beanStore(Class<T> beanType, T bean)
      Adds a bean to the bean store of this operation.

      Equivalent to calling:

      builder.beanStore().add(beanType, bean);

      Type Parameters:
      T - The class to associate this bean with.
      Parameters:
      beanType - The class to associate this bean with.
      bean - The bean. Can be null.
      Returns:
      This object.
    • beanStore

      public <T> RestOpContext.Builder beanStore(Class<T> beanType, T bean, String name)
      Adds a bean to the bean store of this operation.

      Equivalent to calling:

      builder.beanStore().add(beanType, bean, name);

      Type Parameters:
      T - The class to associate this bean with.
      Parameters:
      beanType - The class to associate this bean with.
      bean - The bean. Can be null.
      name - The bean name if this is a named bean. Can be null.
      Returns:
      This object.
    • beanContext

      Returns the bean context sub-builder.
      Returns:
      The bean context sub-builder.
    • createBeanContext

      protected BeanContext.Builder createBeanContext(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the bean context sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new bean context sub-builder.
    • encoders

      Returns the encoder group sub-builder.
      Returns:
      The encoder group sub-builder.
    • encoders

      @SafeVarargs public final RestOpContext.Builder encoders(Class<? extends Encoder>... value)
      Adds one or more encoders to this operation.

      Equivalent to calling:

      builder.encoders().add(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • encoders

      Adds one or more encoders to this operation.

      Equivalent to calling:

      builder.encoders().add(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createEncoders

      protected EncoderSet.Builder createEncoders(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the encoder group sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new encoder group sub-builder.
    • serializers

      Returns the serializer group sub-builder.
      Returns:
      The serializer group sub-builder.
    • serializers

      @SafeVarargs public final RestOpContext.Builder serializers(Class<? extends Serializer>... value)
      Adds one or more serializers to this operation.

      Equivalent to calling:

      builder.serializers().add(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • serializers

      Adds one or more serializers to this operation.

      Equivalent to calling:

      builder.serializers().add(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createSerializers

      protected SerializerSet.Builder createSerializers(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the serializer group sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new serializer group sub-builder.
    • parsers

      Returns the parser group sub-builder.
      Returns:
      The parser group sub-builder.
    • parsers

      @SafeVarargs public final RestOpContext.Builder parsers(Class<? extends Parser>... value)
      Adds one or more parsers to this operation.

      Equivalent to calling:

      builder.parsers().add(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • parsers

      Adds one or more parsers to this operation.

      Equivalent to calling:

      builder.parsers().add(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createParsers

      protected ParserSet.Builder createParsers(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the parser group sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new parser group sub-builder.
    • partSerializer

      Returns the part serializer sub-builder.
      Returns:
      The part serializer sub-builder.
    • partSerializer

      Specifies the part serializer to use for serializing HTTP parts for this operation.

      Equivalent to calling:

      builder.partSerializer().type(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • partSerializer

      Specifies the part serializer to use for serializing HTTP parts for this operation.

      Equivalent to calling:

      builder.partSerializer().impl(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • createPartSerializer

      Instantiates the part serializer sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new part serializer sub-builder.
    • partParser

      Returns the part parser sub-builder.
      Returns:
      The part parser sub-builder.
    • partParser

      Specifies the part parser to use for parsing HTTP parts for this operation.

      Equivalent to calling:

      builder.partParser().type(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • partParser

      Specifies the part parser to use for parsing HTTP parts for this operation.

      Equivalent to calling:

      builder.partParser().impl(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • createPartParser

      protected HttpPartParser.Creator createPartParser(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the part parser sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new part parser sub-builder.
    • jsonSchemaGenerator

      Returns the JSON schema generator sub-builder.
      Returns:
      The JSON schema generator sub-builder.
    • jsonSchemaGenerator

      Specifies the JSON schema generator for this operation.

      Equivalent to calling:

      builder.jsonSchemaGenerator().type(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • jsonSchemaGenerator

      Specifies the JSON schema generator for this operation.

      Equivalent to calling:

      builder.jsonSchemaGenerator().impl(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • createJsonSchemaGenerator

      Instantiates the JSON schema generator sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new JSON schema generator sub-builder.
    • converters

      Returns the response converter list sub-builder.
      Returns:
      The response converter list sub-builder.
    • converters

      @SafeVarargs public final RestOpContext.Builder converters(Class<? extends RestConverter>... value)
      Adds one or more converters to use to convert response objects for this operation.

      Equivalent to calling:

      builder.converters().append(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • converters

      Adds one or more converters to this operation.

      Equivalent to calling:

      builder.converters().append(value);

      Parameters:
      value - The new value.
      Returns:
      This object.
    • createConverters

      protected RestConverterList.Builder createConverters(BeanStore beanStore, Supplier<?> resource)
      Instantiates the response converter list sub-builder.

      Associates one or more converters with a resource class.
      These converters get called immediately after execution of the REST method in the same order specified in the annotation.
      The object passed into this converter is the object returned from the Java method or passed into the RestResponse.setContent(Object) method.

      Can be used for performing post-processing on the response object before serialization.

      When multiple converters are specified, they're executed in the order they're specified in the annotation (e.g. first the results will be traversed, then the resulting node will be searched/sorted).

      Example:

      // Our converter. public class MyConverter implements RestConverter { @Override public Object convert(RestRequest req, Object object) { // Do something with object and return another object. // Or just return the same object for a no-op. } } // Option #1 - Registered via annotation resolving to a config file setting with default value. @Rest(converters={MyConverter.class}) public class MyResource { // Option #2 - Registered via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.converters(MyConverter.class); // Pass in an instance instead. builder.converters(new MyConverter()); } // Option #3 - Registered via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.converters(MyConverter.class); } }

      Notes:
      • When defined as a class, the implementation must have one of the following constructors:
        • public T(BeanContext)
        • public T()
        • public static T create(RestContext)
        • public static T create()
      • Inner classes of the REST resource class are allowed.
      See Also:
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new response converter list sub-builder.
    • guards

      Returns the guard list sub-builder.
      Returns:
      The guard list sub-builder.
    • guards

      @SafeVarargs public final RestOpContext.Builder guards(Class<? extends RestGuard>... value)
      Adds one or more guards to this operation.

      Equivalent to calling:

      builder.guards().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • guards

      Adds one or more guards to this operation.

      Equivalent to calling:

      builder.guards().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createGuards

      protected RestGuardList.Builder createGuards(BeanStore beanStore, Supplier<?> resource)
      Instantiates the guard list sub-builder.

      Instantiates based on the following logic:

      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new guard list sub-builder.
    • matchers

      Returns the matcher list sub-builder.
      Returns:
      The matcher list sub-builder.
    • matchers

      @SafeVarargs public final RestOpContext.Builder matchers(Class<? extends RestMatcher>... value)
      Adds one or more matchers to this operation.

      Equivalent to calling:

      builder.matchers().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • matchers

      Adds one or more matchers to this operation.

      Equivalent to calling:

      builder.matchers().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createMatchers

      protected RestMatcherList.Builder createMatchers(BeanStore beanStore, Supplier<?> resource)
      Instantiates the matcher list sub-builder.

      Associates one or more RestMatchers with the specified method.

      If multiple matchers are specified, ONE matcher must pass.
      Note that this is different than guards where ALL guards needs to pass.

      Notes:
      • When defined as a class, the implementation must have one of the following constructors:
        • public T(RestContext)
        • public T()
        • public static T create(RestContext)
        • public static T create()
      • Inner classes of the REST resource class are allowed.
      See Also:

      Instantiates based on the following logic:

      • Looks for matchers set via any of the following:
      • Looks for a static or non-static createMatchers() method that returns RestMatcher[] on the resource class with any of the following arguments:
      • Resolves it via the bean store registered in this context.
      • Instantiates a RestMatcher[0].
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new matcher list sub-builder.
    • getPathMatchers

      Instantiates the path matchers for this method.
      Returns:
      The path matchers for this method.
    • dotAll

      When enabled, append "/*" to path patterns if not already present.
      Returns:
      This object.
    • defaultRequestHeaders

      Returns the default request headers.
      Returns:
      The default request headers.
    • defaultRequestHeaders

      Adds one or more default request headers to this operation.

      Equivalent to calling:

      builder.defaultRequestHeaders().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createDefaultRequestHeaders

      protected HeaderList createDefaultRequestHeaders(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the default request headers.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default request headers sub-builder.
    • defaultResponseHeaders

      Returns the default response headers.
      Returns:
      The default response headers.
    • defaultResponseHeaders

      Adds one or more default response headers to this operation.

      Equivalent to calling:

      builder.defaultResponseHeaders().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createDefaultResponseHeaders

      protected HeaderList createDefaultResponseHeaders(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the default response headers.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default response headers sub-builder.
    • defaultRequestAttributes

      Returns the default request attributes sub-builder.
      Returns:
      The default request attributes sub-builder.
    • defaultRequestAttributes

      Adds one or more default request attributes to this operation.

      Equivalent to calling:

      builder.defaultRequestAttributes().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createDefaultRequestAttributes

      Instantiates the default request attributes sub-builder.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default request attributes sub-builder.
    • defaultRequestQueryData

      Returns the default request query data.
      Returns:
      The default request query data.
    • defaultRequestQueryData

      Adds one or more default request query data to this operation.

      Equivalent to calling:

      builder.defaultRequestQueryData().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createDefaultRequestQueryData

      protected PartList createDefaultRequestQueryData(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the default request query data.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default request query data sub-builder.
    • defaultRequestFormData

      Returns the default request form data.
      Returns:
      The default request form data.
    • defaultRequestFormData

      Adds one or more default request form data to this operation.

      Equivalent to calling:

      builder.defaultRequestFormData().append(value);

      Parameters:
      value - The values to add.
      Returns:
      This object.
    • createDefaultRequestFormData

      protected PartList createDefaultRequestFormData(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource)
      Instantiates the default request form data.
      Parameters:
      beanStore - The factory used for creating beans and retrieving injected beans.
      parent - The builder for the REST resource class.
      resource - The REST servlet/bean instance that this context is defined against.
      Returns:
      A new default request form data sub-builder.
    • processParameterAnnotations

      protected void processParameterAnnotations()
      Handles processing of any annotations on parameters.

      This includes: Header, Query, FormData.

    • clientVersion

      Client version pattern matcher.

      Specifies whether this method can be called based on the client version.

      The client version is identified via the HTTP request header identified by @Rest(clientVersionHeader) which by default is "Client-Version".

      This is a specialized kind of RestMatcher that allows you to invoke different Java methods for the same method/path based on the client version.

      The format of the client version range is similar to that of OSGi versions.

      In the following example, the Java methods are mapped to the same HTTP method and URL "/foobar".

      // Call this method if Client-Version is at least 2.0. // Note that this also matches 2.0.1. @RestGet(path="/foobar", clientVersion="2.0") public Object method1() {...} // Call this method if Client-Version is at least 1.1, but less than 2.0. @RestGet(path="/foobar", clientVersion="[1.1,2.0)") public Object method2() {...} // Call this method if Client-Version is less than 1.1. @RestGet(path="/foobar", clientVersion="[0,1.1)") public Object method3() {...}

      It's common to combine the client version with transforms that will convert new POJOs into older POJOs for backwards compatibility.

      // Call this method if Client-Version is at least 2.0. @RestGet(path="/foobar", clientVersion="2.0") public NewPojo newMethod() {...} // Call this method if Client-Version is at least 1.1, but less than 2.0. @RestGet(path="/foobar", clientVersion="[1.1,2.0)") @BeanConfig(swaps=NewToOldSwap.class) public NewPojo oldMethod() { return newMethod(); }

      Note that in the previous example, we're returning the exact same POJO, but using a transform to convert it into an older form. The old method could also just return back a completely different object. The range can be any of the following:

      • "[0,1.0)" = Less than 1.0. 1.0 and 1.0.0 does not match.
      • "[0,1.0]" = Less than or equal to 1.0. Note that 1.0.1 will match.
      • "1.0" = At least 1.0. 1.0 and 2.0 will match.
      See Also:
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • debug

      Debug mode.

      Enables the following:

      • HTTP request/response bodies are cached in memory for logging purposes.

      If not sppecified, the debug enablement is inherited from the class context.

      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • defaultCharset

      Default character encoding.

      The default character encoding for the request and response if not specified on the request.

      This overrides the value defined on the RestContext.

      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.defaultCharset"
      • Environment variable "RESTCONTEXT_defaultCharset"
      • "utf-8"
      Returns:
      This object.
    • httpMethod

      HTTP method name.

      Typically "GET", "PUT", "POST", "DELETE", or "OPTIONS".

      Method names are case-insensitive (always folded to upper-case).

      Note that you can use HttpMethod for constant values.

      Besides the standard HTTP method names, the following can also be specified:

      • "*" - Denotes any method.
        Use this if you want to capture any HTTP methods in a single Java method.
        The @Method annotation and/or RestRequest.getMethod() method can be used to distinguish the actual HTTP method name.
      • "" - Auto-detect.
        The method name is determined based on the Java method name.
        For example, if the method is doPost(...), then the method name is automatically detected as "POST".
        Otherwise, defaults to "GET".
      • "RRPC" - Remote-proxy interface.
        This denotes a Java method that returns an object (usually an interface, often annotated with the @Remote annotation) to be used as a remote proxy using RestClient.getRemoteInterface(Class<T> interfaceClass, String url).
        This allows you to construct client-side interface proxies using REST as a transport medium.
        Conceptually, this is simply a fancy POST against the url "/{path}/{javaMethodName}" where the arguments are marshalled from the client to the server as an HTTP content containing an array of objects, passed to the method as arguments, and then the resulting object is marshalled back to the client.
      • Anything else - Overloaded non-HTTP-standard names that are passed in through a &method=methodName URL parameter.
      See Also:
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • maxInput

      The maximum allowed input size (in bytes) on HTTP requests.

      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.

      Example:

      // Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest(maxInput="$C{REST/maxInput,10M}") public class MyResource { // Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builder builder) throws Exception { // Using method on builder. builder.maxInput("10M"); } // Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builder builder) throws Exception { builder.maxInput("10M"); } // Override at the method level. @RestPost(maxInput="10M") public Object myMethod() {...} }

      Notes:
      • String value that gets resolved to a long.
      • Can be suffixed with any of the following representing kilobytes, megabytes, and gigabytes: 'K', 'M', 'G'.
      • A value of "-1" can be used to represent no limit.
      See Also:
      Parameters:
      value - The new value for this setting.
      The default is the first value found:
      • System property "RestContext.maxInput"
      • Environment variable "RESTCONTEXT_MAXINPUT"
      • "100M"

      The default is "100M".
      Returns:
      This object.
    • path

      public RestOpContext.Builder path(String... values)
      Resource method paths.

      Identifies the URL subpath relative to the servlet class.

      Notes:
      • This method is only applicable for Java methods.
      • Slashes are trimmed from the path ends.
        As a convention, you may want to start your path with '/' simple because it make it easier to read.
      Parameters:
      values - The new values for this setting.
      Returns:
      This object.
    • produces

      Supported accept media types.

      Overrides the media types inferred from the serializers that identify what media types can be produced by the resource.
      An example where this might be useful if you have serializers registered that handle media types that you don't want exposed in the Swagger documentation.

      This affects the returned values from the following:

      See Also:
      Parameters:
      values - The values to add to this setting.
      Returns:
      This object.
    • rolesDeclared

      Declared roles.

      A comma-delimited list of all possible user roles.

      Used in conjunction with roleGuard(String) is used with patterns.

      Example:

      @Rest( rolesDeclared="ROLE_ADMIN,ROLE_READ_WRITE,ROLE_READ_ONLY,ROLE_SPECIAL", roleGuard="ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)" ) public class MyResource extends BasicRestServlet { ... }

      See Also:
      Parameters:
      values - The values to add to this setting.
      Returns:
      This object.
    • roleGuard

      Role guard.

      An expression defining if a user with the specified roles are allowed to access methods on this class.

      Example:

      @Rest( path="/foo", roleGuard="ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)" ) public class MyResource extends BasicRestServlet { ... }

      Notes:
      • Supports any of the following expression constructs:
        • "foo" - Single arguments.
        • "foo,bar,baz" - Multiple OR'ed arguments.
        • "foo | bar | bqz" - Multiple OR'ed arguments, pipe syntax.
        • "foo || bar || bqz" - Multiple OR'ed arguments, Java-OR syntax.
        • "fo*" - Patterns including '*' and '?'.
        • "fo* & *oo" - Multiple AND'ed arguments, ampersand syntax.
        • "fo* && *oo" - Multiple AND'ed arguments, Java-AND syntax.
        • "fo* || (*oo || bar)" - Parenthesis.
      • AND operations take precedence over OR operations (as expected).
      • Whitespace is ignored.
      • null or empty expressions always match as false.
      • If patterns are used, you must specify the list of declared roles using Rest.rolesDeclared() or rolesDeclared(String...).
      • Supports SVL Variables (e.g. "$L{my.localized.variable}").
      Parameters:
      value - The values to add to this setting.
      Returns:
      This object.
    • consumes

      Supported content media types.

      Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource.
      An example where this might be useful if you have parsers registered that handle media types that you don't want exposed in the Swagger documentation.

      This affects the returned values from the following:

      See Also:
      Parameters:
      values - The values to add to this setting.
      Returns:
      This object.
    • annotations

      Description copied from class: Context.Builder
      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 on() method can be used with this setting.

      The following example shows the equivalent methods for applying the @Bean annotation:

      // 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. WriterSerializer serializer = JsonSerializer.create().annotations(annotation).build(); // Serialize a bean with the dynamically applied annotation. String json = serializer.serialize(new B());

      The following is the list of annotations builders provided that can be constructed and passed into the builder class:

      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"
      • 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"
      • Fields:
        • Fully qualified:
          • "com.foo.MyClass.myField"
        • Simple:
          • "MyClass.myField"
        • Simple inner class:
          • "MyClass$Inner1$Inner2.myField"
          • "Inner1$Inner2.myField"
          • "Inner2.myField"
      • 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()"
      • A comma-delimited list of anything on this list.
      See Also:
      Overrides:
      annotations in class Context.Builder
      Parameters:
      values - The annotations to register with the context.
      Returns:
      This object.
    • apply

      Description copied from class: Context.Builder
      Applies a set of applied to this builder.

      An AnnotationWork consists of a single pair of AnnotationInfo that represents an annotation instance, and AnnotationApplier which 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. AnnotationList annotations = ClassInfo.of(MyClass.class).getAnnotationList(CONTEXT_APPLY_FILTER); VarResolverSession vrs = VarResolver.DEFAULT.createSession(); AnnotationWorkList work = AnnotationWorkList.of(vrs, annotations); // Apply any settings found on the annotations. WriterSerializer serializer = JsonSerializer .create() .apply(work) .build();

      Overrides:
      apply in class Context.Builder
      Parameters:
      work - The list of annotations and appliers to apply to this builder.
      Returns:
      This object.
    • applyAnnotations

      public RestOpContext.Builder applyAnnotations(Class<?>... fromClasses)
      Description copied from class: Context.Builder
      Applies any of the various @XConfig annotations on the specified class to this context.

      Any annotations found that themselves are annotated with ContextApply will be resolved and applied as properties to this builder. These annotations include:

      Annotations on classes are appended in the following order:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.

      The default var resolver VarResolver.DEFAULT is 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. WriterSerializer serializer = JsonSerializer .create() .applyAnnotations(MyClass.class) .build();

      Overrides:
      applyAnnotations in class Context.Builder
      Parameters:
      fromClasses - The classes on which the annotations are defined.
      Returns:
      This object.
    • applyAnnotations

      Description copied from class: Context.Builder
      Applies any of the various @XConfig annotations on the specified method to this context.

      Any annotations found that themselves are annotated with ContextApply will be resolved and applied as properties to this builder. These annotations include:

      Annotations on methods are appended in the following order:

      1. On the package of the method class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On the method class.
      5. On this method and matching methods ordered parent-to-child.

      The default var resolver VarResolver.DEFAULT is used to resolve any variables in annotation field values.

      Example:

      // 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. WriterSerializer serializer = JsonSerializer .create() .applyAnnotations(MyClass.class.getMethod("myMethod")) .build();

      Overrides:
      applyAnnotations in class Context.Builder
      Parameters:
      fromMethods - The methods on which the annotations are defined.
      Returns:
      This object.
    • cache

      public RestOpContext.Builder cache(Cache<HashKey,? extends Context> value)
      Description copied from class: Context.Builder
      Specifies a cache to use for hashkey-based caching.
      Overrides:
      cache in class Context.Builder
      Parameters:
      value - The cache.
      Returns:
      This object.
    • debug

      Description copied from class: Context.Builder
      Context configuration property:  Debug mode.

      Enables the following additional information during serialization:

      Enables the following additional information during parsing:

      • When bean setters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
      Example:

      // Create a serializer with debug enabled. WriterSerializer serializer = JsonSerializer .create() .debug() .build(); // Create a POJO model with a recursive loop. public class MyBean { public Object f; } MyBean bean = new MyBean(); bean.f = bean; // Throws a SerializeException and not a StackOverflowError String json = serializer.serialize(bean);

      See Also:
      Overrides:
      debug in class Context.Builder
      Returns:
      This object.
    • debug

      public RestOpContext.Builder debug(boolean value)
      Description copied from class: Context.Builder
      Same as Context.Builder.debug() but allows you to explicitly specify the value.
      Overrides:
      debug in class Context.Builder
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • impl

      Description copied from class: Context.Builder
      Specifies a pre-instantiated bean for the Context.Builder.build() method to return.
      Overrides:
      impl in class Context.Builder
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • type

      public RestOpContext.Builder type(Class<? extends Context> value)
      Description copied from class: Context.Builder
      Associates 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.

      Overrides:
      type in class Context.Builder
      Parameters:
      value - The context class that this builder should create.
      Returns:
      This object.