Class ProblemMapperList

java.lang.Object
org.apache.juneau.bean.rfc7807.ProblemMapperList

public class ProblemMapperList extends Object
Aggregator bean for registering multiple ProblemMappers with a single bean-store entry.

The problem-details processor resolves only the unnamed ProblemMapper from the bean store, so a second @Bean public ProblemMapper foo() factory method (even a differently named one) would register a distinct bean that the processor never consults. To register more than one mapper, declare a single @Bean public ProblemMapperList mappers() factory and let the list carry the dispatch order:

@Rest(problemDetails="true") public class MyResource { @Bean public ProblemMapperList problemMappers() { return ProblemMapperList.of(new InsufficientCreditMapper(), new NotFoundMapper()); } }

For the single-mapper case the conventional pattern still works — @Bean public ProblemMapper<MyException> mapper() registers under ProblemMapper.class and the server-side processor picks it up via BeanStore.getBean(ProblemMapper.class) without needing a list wrapper.

See Also:
  • Constructor Details

  • Method Details

    • of

      public static ProblemMapperList of(ProblemMapper<?>... mappers)
      Creates a list populated with the supplied mappers in argument order.
      Parameters:
      mappers - The mappers to add. Can be null, and null entries are skipped; duplicates are allowed and preserved.
      Returns:
      A new ProblemMapperList containing the supplied mappers.
    • append

      Appends a mapper to the end of the list.
      Parameters:
      mapper - The mapper to add. Can be null (no-op).
      Returns:
      This object for fluent chaining.
    • append

      public ProblemMapperList append(Collection<? extends ProblemMapper<?>> values)
      Appends a collection of mappers to the end of the list, in iteration order.
      Parameters:
      values - The mappers to add. Can be null, and null entries are skipped.
      Returns:
      This object for fluent chaining.
    • asList

      public List<ProblemMapper<?>> asList()
      Returns the registered mappers in their declared order.
      Returns:
      An unmodifiable view of the underlying list. Never null.
    • isEmpty

      public boolean isEmpty()
      Returns true when this list contains no mappers.
      Returns:
      true when asList() is empty.