Interface BeanSupplier<T>
- Type Parameters:
T- The type of bean provided by this supplier.
- All Superinterfaces:
Iterable<T>
- All Known Subinterfaces:
BeanChannel<T>
- All Known Implementing Classes:
ListBeanChannel
Extends Iterable so that ClassMeta's existing ITERABLE category picks it
up automatically — no new type category is needed in the framework.
The serializer drives the full lifecycle:
- Calls
begin()before iteration starts - Iterates elements via
Iterable.iterator(), serializing each - If an exception occurs during iteration, calls
onError(Exception) - Always calls
complete()after iteration (likefinally) — whether serialization succeeded or failed. Use this for resource cleanup (close cursors, connections, etc.)
For round-trip support (same property used for both serialization and parsing), use
BeanChannel instead, which extends both BeanSupplier and BeanConsumer.
If a BeanSupplier is encountered during parsing (not serialization), the parser will
throw an IllegalArgumentException with a message recommending BeanConsumer or
BeanChannel.
Example (DB-backed supplier via JDBC cursor):
See Also:
BeanConsumer- Parse-only lifecycle interfaceBeanChannel- Round-trip lifecycle interface (extends both)BeanFactory- Universal factory for DI framework integration- Marshalling
-
Method Summary
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
begin
Called before iteration starts.Use this to open database connections, execute queries, or perform other setup.
- Throws:
Exception- If setup fails.
-
complete
Always called after iteration ends (likefinally).Use this to close database cursors, connections, or release other resources. This method is called whether serialization succeeded or
onError(Exception)rethrew.- Throws:
Exception- If cleanup fails.
-
onError
Called when an exception occurs during iteration.The default implementation rethrows the exception, stopping serialization immediately. Note that
complete()is always called afterward regardless.- Parameters:
e- The exception that occurred during iteration.- Throws:
Exception- If the error cannot be recovered from. Rethroweto stop serialization.
-