Repository navigation
feat: Add TypeReference support for generic types in JSON deserialization - #22442
Conversation
…tion
Add TypeReference overloads to enable List<Bean> and Map<String, Bean> deserialization across all JSON APIs:
- JacksonCodec.decodeAs(JsonNode, TypeReference<T>) for core deserialization
- PendingJavaScriptResult.then/toCompletableFuture with TypeReference
- Element.getProperty(String, Class/TypeReference) for typed property access
- DomEvent.getEventData(Class/TypeReference) for typed event data
This enables usage like:
TypeReference<List<MyDto>> ref = new TypeReference<List<MyDto>>() {};
element.executeJs("return [...]").then(ref, list -> ...);
All 37 JacksonCodecTest tests pass including 5 new TypeReference tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
The Element API |
|
Likely either |
…vent data capture
Add overloaded addEventData methods to DomListenerRegistration that automatically
introspect bean/record structures and add event data expressions for all properties.
This eliminates tedious manual addEventData() calls when working with structured
event data.
Key changes:
- Add BeanUtil.getBeanPropertyPaths() utility for extracting property paths from
bean/record structures using Java Bean introspection
- Add DomListenerRegistration.addEventData(Class<?>) overload that auto-discovers
all properties and nested properties
- Add DomListenerRegistration.addEventData(TypeReference<?>) overload for generic
type support
- Add tests for nested records and simple beans in ElementListenersTest
- Add comprehensive tests for record deserialization in JacksonCodecTest
- Clean separation of concerns: introspection logic in BeanUtil, registration
just iterates over paths
Usage example:
record MouseEventData(EventDetails event, String type) {
record EventDetails(int button, int clientX, int clientY) {}
}
element.addEventListener("click", e -> {
MouseEventData data = e.getEventData(MouseEventData.class);
System.out.println("Button: " + data.event().button());
}).addEventData(MouseEventData.class);
// Automatically adds: event.button, event.clientX, event.clientY, type
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
|
The @eventdata annotation already supported bean types via JacksonCodec deserialization in ComponentEventBus.createEventDataObjects(), but the javadoc incorrectly stated that only primitives and JsonNode were supported. Changes: - Updated EventData javadoc to document full support for: - Beans and DTOs - Java records - Collections (List, Map) - All types Jackson can deserialize - Added comprehensive example showing bean parameter usage - Added test EventWithBeanData demonstrating bean parameters - Added ComponentEventBusTest.eventWithBeanParameter_beanDeserialized() test - Updated json.md to mark all 10/10 features as implemented (100% complete!) This completes JSON/DTO support across all Flow APIs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The bean getter is now |
|
|
This ticket/PR has been released with Vaadin 25.0.0-beta2. |



Add TypeReference overloads to enable List and Map<String, Bean> deserialization across all JSON APIs:
This enables usage like: