Skip to content

Fix JSON BSD codec round-trip for nested struct fields#1742

Merged
kevinherron merged 1 commit into
mainfrom
issues/gh1741
May 17, 2026
Merged

Fix JSON BSD codec round-trip for nested struct fields#1742
kevinherron merged 1 commit into
mainfrom
issues/gh1741

Conversation

@kevinherron

@kevinherron kevinherron commented May 12, 2026

Copy link
Copy Markdown
Contributor

AbstractBsdCodec.encodeField cast every nested-struct value to UaStructuredType before handing it to the nested codec, which failed for JsonObjectCodec since its nested-struct values are raw JsonObjects. Wrap non-UaStructuredType values in BsdStructWrapper before invoking the nested encode, and add a matching decode-side branch in JsonObjectCodec.opcUaToMemberTypeScalar that unwraps BsdStructWrapper returned from nested decodes.

Re-enable JsonBsdCodecTest and GenericBsdCodecTest, which were @Disabled and would otherwise have caught this regression. The round-trip helper in AbstractBsdCodecTest now wraps/unwraps BsdStructWrapper to match the current encode/decode contract.

fixes #1741

AbstractBsdCodec.encodeField cast every nested-struct value to UaStructuredType
before handing it to the nested codec, which failed for JsonObjectCodec since
its nested-struct values are raw JsonObjects. Wrap non-UaStructuredType values
in BsdStructWrapper before invoking the nested encode, and add a matching
decode-side branch in JsonObjectCodec.opcUaToMemberTypeScalar that unwraps
BsdStructWrapper<JsonElement> returned from nested decodes.

Re-enable JsonBsdCodecTest and GenericBsdCodecTest, which were @disabled and
would otherwise have caught this regression. The round-trip helper in
AbstractBsdCodecTest now wraps/unwraps BsdStructWrapper to match the current
encode/decode contract.

fixes #1741
@kevinherron kevinherron added this to the 1.1.3 milestone May 12, 2026
@kevinherron kevinherron modified the milestones: 1.1.3, 1.1.4 May 12, 2026
@kevinherron kevinherron requested a review from Copilot May 12, 2026 19:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes JSON-backed BSD codec round-trip failures when encoding/decoding nested structured fields by aligning the nested-field encode/decode paths with the BsdStructWrapper contract introduced by the earlier refactor. It also re-enables previously disabled tests that would have detected the regression.

Changes:

  • Wrap non-UaStructuredType nested-struct field values in BsdStructWrapper before invoking nested codec encoding (AbstractBsdCodec.encodeField).
  • Unwrap BsdStructWrapper<JsonElement> results from nested decodes when building parent JSON objects (JsonObjectCodec.opcUaToMemberTypeScalar).
  • Re-enable and update JSON/generic BSD codec tests to match the wrapper-based encode/decode contract.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
opc-ua-sdk/dtd-core/src/main/java/org/eclipse/milo/opcua/sdk/core/dtd/AbstractBsdCodec.java Fixes nested structured-field encoding by wrapping non-UaStructuredType values before delegating to nested codecs.
opc-ua-sdk/dtd-core/src/main/java/org/eclipse/milo/opcua/sdk/core/dtd/json/JsonObjectCodec.java Unwraps nested decode results returned as BsdStructWrapper<JsonElement> so nested structs embed correctly in parent JSON.
opc-ua-sdk/dtd-core/src/test/java/org/eclipse/milo/opcua/sdk/core/dtd/AbstractBsdCodecTest.java Updates round-trip helpers to wrap inputs and unwrap decoded outputs to reflect current codec contracts.
opc-ua-sdk/dtd-core/src/test/java/org/eclipse/milo/opcua/sdk/core/dtd/json/JsonBsdCodecTest.java Re-enables JSON BSD codec tests, including nested-struct coverage.
opc-ua-sdk/dtd-core/src/test/java/org/eclipse/milo/opcua/sdk/core/dtd/GenericBsdCodecTest.java Re-enables generic BSD codec tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kevinherron kevinherron merged commit 6e3ae3a into main May 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON BSD codec fails on nested struct fields

2 participants