Annotation Interface Mixin


@Target({}) @Retention(RUNTIME) public @interface Mixin
Rich mixin definition for the @Rest(mixinDefs=...) attribute.

Declares a mixin class and lets the host override selected @Rest-level settings for that mixin's mixed-in endpoints — in one place, without subclassing or editing the mixin class. This is the host-side complement to @Rest(mixins=...) (which takes bare classes and offers no override hook).

Example:

@Rest( mixinDefs=@Mixin(type=FooMixin.class, guards=AdminGuard.class) ) public class MyResource { ... }

Here AdminGuard is applied to FooMixin's endpoints as declared by the host, without FooMixin having to declare it.

Override semantics

The override slots mirror the same @Rest attributes and resolve through the existing host→mixin inheritance chain, exactly as if the value had been declared on the mixin class itself, but at the most-derived position so a host override wins over the mixin class's own same-property declaration:

  • List-shaped (guards, converters, encoders, serializers, parsers, responseProcessors, restOpArgs, default headers/attributes, produces/consumes) — appended after the host chain that the mixin inherits.
  • Replace-shaped (partSerializer, partParser, defaultAccept/defaultContentType/defaultCharset, maxInput, roleGuard/rolesDeclared, messages) — the host override wins when set.

noInherit() is the @Mixin's own inheritance-cutoff list, applied to this mixin's sub-context: a token here cuts the host→mixin inheritance walk for that property (same token set as Rest.noInherit()). The host override is authoritative but overridable by these noInherit rules — e.g. @Mixin(type=X.class, noInherit="guards") removes the host's guard chain from X's endpoints entirely.

path()/paths() re-mount the mixin's endpoints under host-chosen prefix(es).

Merging a mixin's list attributes into the host

The override slots above apply the host's values to the mixin's endpoints. The separate opt-in mergeIntoHost() directive does the reverse: it appends the mixin's own list-shaped @Rest attributes (e.g. responseProcessors) into the host's own chains, so the host's own @RestOp methods pick them up too. It defaults to false (host endpoints see only the host's chain, as before) and is only settable on a rich @Mixin — see mergeIntoHost().

See Also:
Since:
10.0.0
  • Element Details

    • type

      The mixin class to compose into the host resource.

      Required. Equivalent to a bare entry in Rest.mixins(), but with the override slots below.

      Returns:
      The mixin class.
    • mergeIntoHost

      boolean mergeIntoHost
      Opt-in directive: fold this mixin's list-shaped @Rest attributes into the host resource's own corresponding chains (not just the mixin's own endpoints).

      By default (false) a mixin's list-shaped @Rest contributions apply only to the mixin's own endpoints — a host's own @RestOp methods see only the host's chain (the standard mixin inheritance rule "host's chain runs first, then the mixin's appended; host endpoints see only the host's chain"), so a mixin's e.g. responseProcessors are effectively dropped for host endpoints. Setting this to true additionally appends the adopted mixin's own list-shaped @Rest attributes to the end of the host's corresponding chains, so the host's own endpoints pick them up too.

      The folded set is the list-shaped contribution attributes: serializers, parsers, encoders, converters, guards, responseProcessors, restOpArgs, defaultRequestHeaders, defaultResponseHeaders, defaultRequestAttributes, produces, and consumes. Replace-shaped attributes (e.g. partSerializer, partParser) and host-only attributes (path/paths/children) are never folded. Same-class de-duplication applies, so a class the host already declares is not added twice.

      This is strictly opt-in: it has no effect on a bare Rest.mixins() entry (which cannot set it) or a @Mixin that leaves it false, so existing resources are unaffected. The mixin still mounts its own endpoints as usual — this directive is purely additive to the host chain.

      Example:

      // Auto-wire JspMixin's JspViewRenderer into the host so the host's own @RestOp methods can // return JspView (no need to also list JspViewRenderer in the host's @Rest(responseProcessors)). @Rest(mixinDefs=@Mixin(type=JspMixin.class, mergeIntoHost=true)) public class AppResource extends RestServlet { ... }

      Returns:
      The annotation value.
      Since:
      10.0.0
      Default:
      false
    • guards

      Class<? extends RestGuard>[] guards
      Host-declared guards override for this mixin's endpoints (appended after the host chain).
      Returns:
      The annotation value.
      Default:
      {}
    • roleGuard

      Host-declared roleGuard override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      ""
    • rolesDeclared

      Host-declared rolesDeclared override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      ""
    • converters

      Host-declared converters override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • encoders

      Class<? extends Encoder>[] encoders
      Host-declared encoders override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • serializers

      Host-declared serializers override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • parsers

      Host-declared parsers override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • responseProcessors

      Host-declared responseProcessors override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • restOpArgs

      Class<? extends RestOpArg>[] restOpArgs
      Host-declared restOpArgs override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • partSerializer

      Host-declared partSerializer override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      org.apache.juneau.marshall.httppart.HttpPartSerializer.Void.class
    • partParser

      Host-declared partParser override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      org.apache.juneau.marshall.httppart.HttpPartParser.Void.class
    • messages

      Host-declared messages override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      ""
    • defaultRequestHeaders

      Host-declared defaultRequestHeaders override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • defaultResponseHeaders

      Host-declared defaultResponseHeaders override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • defaultRequestAttributes

      Host-declared defaultRequestAttributes override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • produces

      Host-declared produces override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • consumes

      Host-declared consumes override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      {}
    • defaultAccept

      Host-declared defaultAccept override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      ""
    • defaultContentType

      Host-declared defaultContentType override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      ""
    • defaultCharset

      Host-declared defaultCharset override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      ""
    • maxInput

      Host-declared maxInput override for this mixin's endpoints.
      Returns:
      The annotation value.
      Default:
      ""
    • path

      Host-chosen single mount prefix for this mixin's endpoints (re-mount).
      Returns:
      The annotation value.
      Default:
      ""
    • paths

      Host-chosen multi-mount prefixes for this mixin's endpoints (re-mount).
      Returns:
      The annotation value.
      Default:
      {}
    • noInherit

      Inheritance-cutoff list for this mixin's sub-context.

      Each token names a property whose host→mixin inheritance walk is cut for this mixin (same token set as Rest.noInherit()). Authoritative over the host override slots above.

      Returns:
      The annotation value.
      Default:
      {}