Re: [go-nuts] Re: Is it possible to unmarshall Json by selecting the struct from a field in the Json?

2018-03-28 Thread Jonathan Yu
You can also keep a map between the string form and the reflect.Type to instantiate, something like https://play.golang.org/p/XCfpjQwumkZ However, the Go proverb is true: "Reflection is never clear" https://go-proverbs.github.io/ On Wed, Mar 28, 2018 at 5:58 AM,

[go-nuts] Re: Is it possible to unmarshall Json by selecting the struct from a field in the Json?

2018-03-28 Thread gary . willoughby
Thanks. I read that blog post earlier and presents two different ways of handling this. Each maintains a list of switch cases and constants respectively so still not entirely dynamic. I'll probably just go with a switch then. On Wednesday, 28 March 2018 13:25:47 UTC+1, Andrei Tudor Călin

[go-nuts] Re: Is it possible to unmarshall Json by selecting the struct from a field in the Json?

2018-03-28 Thread Andrei Tudor Călin
It isn't really possible to do so because there is no nice and type safe way of getting from a string in the JSON to a Go type, and a value of said type. You must write a little bit of extra code. This article: http://eagain.net/articles/go-dynamic-json/ presents a good approach. On Wednesday,