Skip to content

ElementalNode classes fail runtime type checks #29

@javier-godoy

Description

@javier-godoy

Describe the bug

The ElementalNode classes wrap Jackson's nodes (such as ObjectNode or ArrayNode) while implementing the JsonValue interface from Elemental JSON API. However, these classes do not implement the specific Elemental interfaces (such as JsonObject or JsonArray).

class ElementalObjectNode extends ObjectNode implements UnsupportedJsonValueImpl {

The utility method convertToClientCallableResult uses a generic constraint

<T extends JsonValue> T convertToClientCallableResult(T object);

While the code compiles successfully, this results in a runtime failure whenever a client callable method attempts to cast the return value to a specific subtype.

Expected behavior

The result of convertToClientCallableResult must actually implement the expected subtype interface.

Minimal reproducible example

Consider a typical migration helper usage:

public JsonObject getJsonData() {
    JsonObject result = ... 
    
    // The helper returns JsonObject, so it compiles.
    // However, the JVM cannot cast the resulting object to JsonObject at runtime.
    return JsonMigration.convertToClientCallableResult(result);
}

Add-on Version

0.9.1

Vaadin Version

25.0.2

Additional information

To complicate things more, the specific Elemental interfaces cannot be implemented directly in the Java source code because of a fundamental conflict in method signatures between the two APIs.

  • Elemental API: In the subtype interfaces mutation methods are designed to return void.
  • Jackson API: The mutation methods in the node classes are designed to be fluent.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions