Re: [go-nuts] Unmarshal variable JSON structures

2022-12-26 Thread Marcin Romaszewicz
Here is an example of what I mean. https://go.dev/play/p/O6KIsxmSeaN This is why I wrote a code generator, it's tedious by hand :) On Mon, Dec 26, 2022 at 11:08 AM Marcin Romaszewicz wrote: > This is a very annoying problem, and one that we hit a lot in my project ( >

Re: [go-nuts] Unmarshal variable JSON structures

2022-12-26 Thread Marcin Romaszewicz
This is a very annoying problem, and one that we hit a lot in my project ( https://github.com/deepmap/oapi-codegen), where we generate Go models from OpenAPI specs, and the OpenAPI "AnyOf" or "OneOf" schema does precisely this. You can partially unmarshal; store your "type" field in a typed

[go-nuts] Unmarshal variable JSON structures

2022-12-26 Thread Andrew Burian
Hey all, wondering if there's an existing best practice for this so I'm not reinventing the wheel. It's frustratingly common to have APIs where the response JSON can be one of several distinct objects, and the indicator of which object has been returned is itself a property of the object. So you