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 because marshalling has not been implemented for orderedmap.
I'm not sure what this would actually look like because it must be reasonable that the order would also be retained in the data structure. So simply using a JSON object would not be sufficient.
Since there are multiple ways marshalling and unmarshalling could work so it's best to leave it up to the implementation. Here is one example that might suit your needs:
This is because marshalling has not been implemented for orderedmap.
I'm not sure what this would actually look like because it must be reasonable that the order would also be retained in the data structure. So simply using a JSON object would not be sufficient.
Since there are multiple ways marshalling and unmarshalling could work so it's best to leave it up to the implementation. Here is one example that might suit your needs:
marshaling and unmarshaling may cause unexpected issue, like int type will be marshal into int64 type in your example https://play.golang.org/p/IjP7E3lRMhT
If the order and specific data types must be retained in the serialized value then you will need a more complex marshaller to suit your specific needs.
This is because marshalling has not been implemented for orderedmap.
I'm not sure what this would actually look like because it must be reasonable that the order would also be retained in the data structure. So simply using a JSON object would not be sufficient.
Since there are multiple ways marshalling and unmarshalling could work so it's best to leave it up to the implementation. Here is one example that might suit your needs:
Activity
elliotchance commentedon Apr 1, 2020
This is because marshalling has not been implemented for
orderedmap.I'm not sure what this would actually look like because it must be reasonable that the order would also be retained in the data structure. So simply using a JSON object would not be sufficient.
Since there are multiple ways marshalling and unmarshalling could work so it's best to leave it up to the implementation. Here is one example that might suit your needs:
https://play.golang.org/p/LjOrp4k6lqf
abusizhishen commentedon Jul 9, 2020
marshaling and unmarshaling may cause unexpected issue, like int type will be marshal into int64 type in your example
https://play.golang.org/p/IjP7E3lRMhT
elliotchance commentedon Jul 9, 2020
If the order and specific data types must be retained in the serialized value then you will need a more complex marshaller to suit your specific needs.
89trillion-feiyang commentedon Jun 30, 2021
The structure after serialization is not what I want.
According to your code result is
[ [ "2", { "a": "2", "b": "7" } ], [ "3", { "a": "3", "b": "1" } ] ]Expect:
{ "2": { "a": 3, "b": 4 } }elliotchance commentedon Jul 1, 2021
@89trillion-feiyang - you can serialize it in any format you want. Here's some sample code to produce that: https://play.golang.org/p/tKGpbGCpFbC
Keep in mind some caveats with that:
89trillion-feiyang commentedon Jul 2, 2021
OK. Thanks! I solved it.
GitRowin commentedon Dec 9, 2024
Consider using my library, built on top of this library: https://github.com/GitRowin/orderedmapjson