Skip to content

Commit aa010ea

Browse files
javier-godoypaodb
authored andcommitted
docs(readme): add documentation for new features
1 parent 4b5a150 commit aa010ea

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Provides a compatibility layer for JSON handling to abstract away breaking chang
1313
- **Zero-effort migration**: Write your code once and run it seamlessly on Vaadin 14, 23, 24 and 25
1414
- **Automatic version detection**: Detects the runtime Vaadin version and uses the appropriate JSON handling strategy
1515
- **Drop-in replacement**: Simple static methods that replace version-specific APIs
16+
- **Client Callable compatibility**: Mechanisms to handle JSON arguments and return types in `@ClientCallable` methods.
17+
- **JsonSerializer and JsonCodec**: Includes `JsonSerializer` and `JsonCodec` classes for serialization and deserialization of elemental JSON values.
1618

1719

1820
## Download release
@@ -117,12 +119,39 @@ When a `@ClientCallable` method needs to return a JSON value, use `convertToClie
117119

118120
```java
119121
@ClientCallable
120-
public Object getJsonData() {
122+
public JsonValue getJsonData() {
121123
JsonValue json = ...;
122124
return JsonMigration.convertToClientCallableResult(json);
123125
}
124126
```
125127

128+
## Receiving JSON in ClientCallable methods
129+
130+
If the method receives `JsonValue` as an argument, it cannot be annotated with `ClientCallable` because of compatibility issues. `LegacyClientCallable` should be used instead.
131+
132+
To use `LegacyClientCallable`, you must use instrumentation. This can be done via `JsonMigration.instrumentClass` or by using `InstrumentedRoute` / `InstrumentationViewInitializer`.
133+
134+
**Note:** Instrumentation is a complex mechanism. While it might warrant a rewrite of the affected code, it is offered here to preserve compatibility with existing implementations.
135+
136+
```java
137+
@InstrumentedRoute("legacy-view")
138+
public class ViewWithElementalCallables extends Div {
139+
@LegacyClientCallable
140+
public void receiveJson(JsonValue json) {
141+
// ...
142+
}
143+
}
144+
145+
// Register via META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener
146+
// or use `@SpringComponent` with Spring.
147+
public class ViewInitializerImpl extends InstrumentationViewInitializer {
148+
@Override
149+
public void serviceInit(ServiceInitEvent event) {
150+
registerInstrumentedRoute(ViewWithElementalCallables.class);
151+
}
152+
}
153+
```
154+
126155
## Direct Usage
127156

128157
The helper methods can also be used directly from the `JsonMigration` class:

0 commit comments

Comments
 (0)