Class ListBeanChannel<T>

java.lang.Object
org.apache.juneau.commons.function.ListBeanChannel<T>
Type Parameters:
T - The type of bean stored in this channel.
All Implemented Interfaces:
Iterable<T>, Consumer<T>, BeanChannel<T>, BeanConsumer<T>, BeanSupplier<T>, ThrowingConsumer<T>

public class ListBeanChannel<T> extends Object implements BeanChannel<T>
A simple in-memory BeanChannel implementation backed by an ArrayList.

Collects parsed elements into an in-memory list on the parser side, and iterates over the list on the serializer side. No factory or DI framework required — instantiated directly via no-arg constructor.

This is the default built-in implementation suitable for use cases where holding all elements in memory is acceptable. For large datasets or database-backed scenarios, implement BeanChannel (or BeanConsumer / BeanSupplier) directly.

Example (getter-only round-trip property):

public class ItemCollection { private final ListBeanChannel<Item> items = new ListBeanChannel<>(); @BeanProp(elementType=Item.class) public ListBeanChannel<Item> getItems() { return items; } // No setter needed — parser calls acceptThrows() on the existing instance }

See Also:
  • Constructor Details

  • Method Details

    • acceptThrows

      public void acceptThrows(T item)
      Description copied from interface: ThrowingConsumer
      Performs this operation on the given argument, potentially throwing a checked exception.

      This is the functional method that implementations must provide. It allows checked exceptions to be thrown directly, unlike the standard Consumer.accept(Object) method.

      Example:

      ThrowingConsumer<String> validator = (value) -> { if (value == null || value.isEmpty()) { throw new ValidationException("Value cannot be empty"); } }; try { validator.acceptThrows(""); } catch (ValidationException e) { // Handle checked exception }

      Specified by:
      acceptThrows in interface ThrowingConsumer<T>
      Parameters:
      item - The input argument.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • getList

      public List<T> getList()
      Returns the underlying list of elements.
      Returns:
      The list of elements collected during parsing, or to be serialized.