spyzhov / ajson

Abstract JSON for Golang with JSONPath support
MIT License
247 stars 23 forks source link

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

Open tpoxa opened 1 year ago

tpoxa commented 1 year ago

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.

spyzhov commented 1 year ago

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.