Skip to content

LogicalLink: writeValueAsString / readValue is not round-trippable for OperatorIdentity fields #5042

Closed

Description

@aglinxinyuan

Root cause

amber/src/main/scala/org/apache/texera/workflow/LogicalLink.scala declares only a single @JsonCreator overload that accepts raw String op-ids:

@JsonCreator
def this(
    @JsonProperty("fromOpId") fromOpId: String,
    fromPortId: PortIdentity,
    @JsonProperty("toOpId") toOpId: String,
    toPortId: PortIdentity
) = this(OperatorIdentity(fromOpId), fromPortId, OperatorIdentity(toOpId), toPortId)

But objectMapper.writeValueAsString serializes OperatorIdentity as an object {"id": "op-A"} (its scalapb case-class shape), not as a raw string. Jackson dispatches deserialization to the only @JsonCreator it knows — the String overload — which then rejects the object value.

Reproduce

val original = LogicalLink(
  OperatorIdentity("op-A"), PortIdentity(0),
  OperatorIdentity("op-B"), PortIdentity(1)
)
val json = objectMapper.writeValueAsString(original)
// json = {"fromOpId":{"id":"op-A"}, "fromPortId":..., "toOpId":{"id":"op-B"}, "toPortId":...}
objectMapper.readValue(json, classOf[LogicalLink])
// throws com.fasterxml.jackson.databind.exc.MismatchedInputException:
//   Cannot deserialize value of type `java.lang.String` from Object value

The current characterization is pinned in
LogicalLinkSpec
("NOT round-trip through writeValueAsString …") so the asymmetry can't drift silently.

Surface

Surface Write → Read
Frontend-saved workflow JSON (fromOpId: "op-A", string form) works — String overload dispatched
objectMapper.writeValueAsString(link) → objectMapper.readValue(json, classOf[LogicalLink]) (object form) broken — String overload rejects the object value

Before → after

Before After
treeToValue from string-shaped JSON ✅ ✅ (unchanged)
writeValueAsString → readValue round-trip ❌ MismatchedInputException ✅
Characterization test in LogicalLinkSpec pinned asymmetry needs to flip to a passing round-trip assertion alongside the fix

Proposed fix (pick one)

  1. Add a second @JsonCreator overload that accepts an object-shape OperatorIdentity, OR
  2. Annotate fromOpId / toOpId with a custom @JsonDeserialize that handles both shapes (string and {"id": ...}).

Tracked by

The asymmetry is currently characterized (not asserted as passing) in LogicalLinkSpec — see review thread in PR #4956. When the fix lands, that test must be flipped to assert a successful round-trip.

Priority

P3 - Low (no production data loss; serialization-path-only)

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions