Skip to main content

RestOpContext

The RestOpContext object is the workhorse class for an individual RestOp-annotated method. Every class annotated with @RestOp ends up with an instance of this object.

Similar to RestContext, the object is read-only and unchangeable and is initialized with all of the various annotations pulled from the method.

All functionality available through annotations have programmatic equivalents through the builder of this class.

To access the builder for these objects, simply implement the following init method that will be called for each RestOp-annotated method.

// Use an init hook with RestOpContext.Builder as a parameter.
@RestInit
public void init(RestOpContext.Builder builder) throws Exception {
builder
.beanContext(x -> x.swaps(TemporalCalendarSwap.Rfc1123DateTime.class))
.debugEnablement(CONDITIONAL);
}

There are multiple ways to programmatically alter how RestOpContext behaves.

The most straightforward are the following builder methods which are direct equivalents to values defined on the RestOp annotation:

RestOpContext.BuilderclientVersion(String)consumes(MediaType...)debug(Enablement)defaultCharset(Charset)dotAll()httpMethod(String)maxInput(String)path(String...)produces(MediaType...)roleGuard(String)rolesDeclared(String...)

For more complex configurations, access to sub-builders is provided via the following methods:

RestOpContext.Builderconverters()defaultClasses()defaultRequestAttributes()defaultRequestFormData()defaultRequestHeaders()defaultRequestQueryData()defaultResponseHeaders()encoders()guards()jsonSchemaGenerator()matchers()parsers()partParser()partSerializer()serializers()
note

It is also possible to override methods on the RestOpContext class itself by providing your own specialized subclass via the RestOpContext.Builder.type(Class) method.