You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my second bug report around any, so I'm guessing that any support in version 5 has some challenges. This bug isn't as serious as the first one, as this can be worked around and my guess would require substantial work. But I wanted to note it for the authors.
You cannot decode back into the same structure, it gives an error. The error is different in version 4 and 5 but are likely related to the same problem with handling the reflection.
Expected Behavior
It should decode back into the structure. There are two ways that it could do this:
encoding/json way
json-experiment way (better)
The original encoding/json would decode it, but replace Record with map[string]any. That is not ideal and unexpected. But it does kinda work.
The better approach is the json-experiment way. This package is likely to be incorporated as encoding/json/v2. It decodes it into the structure.
Current Behavior
v5: panic: reflect: reflect.Value.SetString using unaddressable value
v4: panic: Decode(nonsettable string)
Possible Solution
Adopt the decoding practices of json-experiment around any types.
Well, you can still decode into plainany with v4. Because of the other bug I left, you can't use version 5.
But this does mean you have to then manually convert from map[string]any to the concrete type. Not the end of the world.
The text was updated successfully, but these errors were encountered:
element-of-surprise
changed the title
reflect.Value.SetString using unaddressable value on concrete values contained within any structuresreflect.Value.SetString using unaddressable value on concrete values contained within any structures
Apr 21, 2024
This is my second bug report around
any
, so I'm guessing thatany
support in version 5 has some challenges. This bug isn't as serious as the first one, as this can be worked around and my guess would require substantial work. But I wanted to note it for the authors.Given a structure to encode and decode:
(Yeah, I know....)
You cannot decode back into the same structure, it gives an error. The error is different in version 4 and 5 but are likely related to the same problem with handling the reflection.
Expected Behavior
It should decode back into the structure. There are two ways that it could do this:
encoding/json
wayjson-experiment
way (better)The original
encoding/json
would decode it, but replaceRecord
withmap[string]any
. That is not ideal and unexpected. But it does kinda work.The better approach is the
json-experiment
way. This package is likely to be incorporated as encoding/json/v2. It decodes it into the structure.Current Behavior
v5: panic: reflect: reflect.Value.SetString using unaddressable value
v4: panic: Decode(nonsettable string)
Possible Solution
Adopt the decoding practices of json-experiment around
any
types.Steps to Reproduce
https://go.dev/play/p/5vpaqDRrD5d
Here is JSON experiment doing the same type of encode/decode:
https://go.dev/play/p/Slea4ZbvjR7
Context (Environment)
Well, you can still decode into plain
any
with v4. Because of the other bug I left, you can't use version 5.But this does mean you have to then manually convert from map[string]any to the concrete type. Not the end of the world.
The text was updated successfully, but these errors were encountered: