Class JsonMigration
java.lang.Object
com.flowingcode.vaadin.jsonmigration.JsonMigration
Provides a compatibility layer for JSON handling to abstract away breaking changes
introduced in Vaadin version 25.
This utility class detects the runtime version and uses version-specific helpers to ensure that code calling its methods does not need to be aware of underlying Vaadin API changes.
- Author:
- Javier Godoy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends elemental.json.JsonValue>
TconvertToClientCallableResult(T object) Converts a given Java object into the return type of amethod.static elemental.json.JsonValueconvertToJsonValue(Object object) Converts a given Java object into aJsonValue.executeJs(Element element, String expression, Serializable... parameters) Asynchronously runs the given JavaScript expression in the browser in the context of this element.static elemental.json.JsonObjectgetEventData(DomEvent event) Gets additional data related to the event.static voidsetPropertyJson(Element element, String name, elemental.json.JsonValue json) Sets a JSON-valued property on a givenElement, transparently handling version-specific method signatures.
-
Constructor Details
-
JsonMigration
public JsonMigration()
-
-
Method Details
-
convertToClientCallableResult
public static <T extends elemental.json.JsonValue> T convertToClientCallableResult(T object) Converts a given Java object into the return type of amethod. In Vaadin 25, this method convertsJsonValueintoJsonNode.- Parameters:
object- the object to convert- Returns:
- an
Objectsuitable to use as the result of aClientCallablemethod.
-
convertToJsonValue
Converts a given Java object into aJsonValue.This method delegates the conversion to a version-specific helper to handle any differences in the serialization process.
- Parameters:
object- the object to convert- Returns:
- the
JsonValuerepresentation of the object
-
setPropertyJson
Sets a JSON-valued property on a givenElement, transparently handling version-specific method signatures.This method uses reflection to call the appropriate
setPropertyJsonmethod on theElementclass, which has a different signature for its JSON parameter in library versions before and after Vaadin 25.- Parameters:
element- theElementon which to set the propertyname- the name of the property to setjson- theJsonValueto be set as the property's value
-
executeJs
public static ElementalPendingJavaScriptResult executeJs(Element element, String expression, Serializable... parameters) Asynchronously runs the given JavaScript expression in the browser in the context of this element.- Parameters:
element- theElementon which to run the JavaScript expressionexpression- the JavaScript expression to invokeparameters- parameters to pass to the expression- Returns:
- a pending result that can be used to get a value returned from the expression
- See Also:
-
getEventData
Gets additional data related to the event.- Parameters:
event- theDomEventfrom which to retrieve the data- Returns:
- a JSON object containing event data, never
null - See Also:
-