ajson icon indicating copy to clipboard operation
ajson copied to clipboard

ajson.Node from interface or map[string]interface{}

Open tpoxa opened this issue 2 years ago • 1 comments

Hey. When I have something from above to query using ajson I need to marshal to binary and then unmarshal with ajson. Is any way to do that better? Thanks.

tpoxa avatar Dec 17 '22 19:12 tpoxa

Hey! Thanks for the question. Unfortunately, that's the only way for now. ajson uses its own internal unmarshaller build on top of the state transition table, and its own marshaller into the basic types. To add the possibility to (un)marshal structs, I have to add a new layer of reflection and support a json.Unmarshaler interface, but that will slow logic a lot. And regarding map[string]interface{} - problem is the same (1) interface{} can be a struct type, so it will cause the previously described problem, and (2) it can be a slice, so to solve it for golang 1.17 and older (before generics) the only way is reflection again.

So, for the current version, json.Marshal + ajson.Unmarshal is the only way how to do it properly.

In the next (v1) version, I will think about how to solve this restriction. Probably, I will just raise a supported version of golang up to 1.18.

spyzhov avatar Dec 20 '22 10:12 spyzhov