Skip to content

Use encoding.TextMarshaler for string-valued types - #567

Open
felix-kaestner wants to merge 1 commit into
mainfrom
encoding-text
Open

felix-kaestner wants to merge 1 commit into
mainfrom
encoding-text

Conversation

@felix-kaestner

Copy link
Copy Markdown
Collaborator

Replace json.Marshaler/json.Unmarshaler with the encoding package TextMarshaler/TextUnmarshaler interfaces on provider types that serialize as a plain string value.

TextMarshaler is more semantically correct for these types: json.Marshaler declares "I can be any JSON value" (object, array, number), while TextMarshaler declares "I am a string" which matches what these types actually are.

encoding/json calls MarshalText/UnmarshalText automatically, so JSON encoding continues to work unchanged. Additionally, the text interfaces are recognized by other encoders (YAML, XML, CSV), making the types usable in more contexts.

UnmarshalText receives the raw string bytes with JSON quotes already stripped, removing the need to json.Unmarshal into an intermediate string variable first.

Replace json.Marshaler/json.Unmarshaler with the encoding
package TextMarshaler/TextUnmarshaler interfaces on provider
types that serialize as a plain string value.

TextMarshaler is more semantically correct for these types:
json.Marshaler declares "I can be any JSON value" (object,
array, number), while TextMarshaler declares "I am a string"
which matches what these types actually are.

encoding/json calls MarshalText/UnmarshalText automatically,
so JSON encoding continues to work unchanged. Additionally,
the text interfaces are recognized by other encoders (YAML,
XML, CSV), making the types usable in more contexts.

UnmarshalText receives the raw string bytes with JSON quotes
already stripped, removing the need to json.Unmarshal into an
intermediate string variable first.

Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
@github-actions

Copy link
Copy Markdown

Merging this branch changes the coverage (1 decrease, 2 increase)

Impacted Packages Coverage Δ 🤖
github.com/ironcore-dev/network-operator/internal/provider/cisco/iosxr 37.28% (+0.22%) 👍
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos 7.15% (+0.02%) 👍
github.com/ironcore-dev/network-operator/internal/provider/openconfig 9.04% (-0.01%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/ironcore-dev/network-operator/internal/provider/cisco/iosxr/bgp_peer.go 63.64% (+4.06%) 44 (-3) 28 16 (-3) 👍
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos/bgp.go 25.81% (+1.19%) 62 (-3) 16 46 (-3) 👍
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos/intf.go 33.10% (+0.68%) 142 (-3) 47 95 (-3) 👍
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos/provider.go 0.24% (+0.00%) 3305 (-1) 8 3297 (-1) 👍
github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos/vlan.go 20.00% (+3.33%) 15 (-3) 3 12 (-3) 👍
github.com/ironcore-dev/network-operator/internal/provider/openconfig/banner.go 0.00% (ø) 16 (+1) 0 16 (+1)

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

@hardikdr hardikdr added the area/switch-automation Automation processes for network switch management and operations. label Sep 17, 2026
@hardikdr hardikdr added this to Roadmap Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/switch-automation Automation processes for network switch management and operations. size/L

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants