Interface Stringifier<T>

Type Parameters:
T - The type of object this stringifier handles
All Superinterfaces:
BiFunction<BeanConverter,T,String>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Functional interface for converting objects of a specific type to their string representation.

Stringifiers provide custom string conversion logic for specific object types within the Bean-Centric Testing framework. They enable precise control over how objects are displayed in test assertions and error messages, going beyond simple toString() calls.

Usage Examples:

// Simple custom format Stringifier<LocalDate> dateStringifier = (conv, date) -> date.format(DateTimeFormatter.ISO_LOCAL_DATE); // Complex nested object formatting Stringifier<Person> personStringifier = (conv, person) -> person.getName() + " (" + conv.stringify(person.getAddress()) + ")"; // Conditional formatting Stringifier<Order> orderStringifier = (conv, order) -> { var status = order.getStatus(); return status == OrderStatus.COMPLETED ? "Order #" + order.getId() + " [DONE]" : "Order #" + order.getId() + " [" + status + "]"; };

Registration:

var converter = BasicBeanConverter.builder() .defaultSettings() .addStringifier(LocalDate.class, dateStringifier) .addStringifier(Person.class, personStringifier) .addStringifier(Order.class, orderStringifier) .build();

Best Practices:
  • Use the converter parameter for recursive conversion of nested objects
  • Keep output concise but informative for test readability
  • Handle edge cases gracefully (empty collections, special values)
  • Consider test context - focus on properties relevant to testing
See Also: