edgexfoundry/go-mod-core-contracts

Add UnmarshalObjectValue helper function to Reading DTO

Closed this issue ยท 0 comments

๐Ÿš€ Feature Request

Relevant Package [REQUIRED]

Reading DTO

Description [REQUIRED]

ObjectValue JSON gets un-marshaled to a `map[string]any` since the JSON marshaller doesn't have the type info for it. Need a help function that will handle un-marshaling the Object Value to a known type

Describe the solution you'd like

Add the UnmarshalObjectValue() helper function to the Reading DTO
func (b BaseReading) UnmarshalObjectValue(target any) error

function must marshal the current reading ObjectValue to JSON and then un-marshal the JSON into the passed in target.

Usage:

target myTYpe{}
err := myReading.UnmarshalObjectValue(&myType)

Describe alternatives you've considered

Have you considered any alternative solutions or workarounds?