i am working with a service that have both a websocket for live data and a api for historical data
the JSON looks similar and i would like to decode it to the same object
the only difference is that in the live one variable is a number but as a string and with the historical data the number is an int.
and preferably i would like to not have to create 2 almost identical decodable objects.
have anyone tried something similar.
2
Answers
I think you need a wrapper for that case of some sort. To make it as convenient as possible you could use a property wrapper for this
You have to define a single type (
Int
orString
) for your data structure and useinit
withDecoder
to make a custom parsing.