3 ms·
It sounds like you're parsing the JSON straight into your business objects, which is the source of the problem. You need an intermediate class which represents
by curveship 10y ago
It sounds like you're parsing the JSON straight into your business objects, which is the source of the problem. You need an intermediate class which represents a strongly-typed version of the JSON message. So JSON.net goes from a JSON string into this message object, then you write your own code (or, if it works for you, use a tool like automapper), to go from that into your business classes.
- adrianratnapala 10y agoThis is what I settled on -- at least in the hard cases. And if I understand his acronyms, it's also what @mythz is recommending. Perhaps I should have done it for the easy cases as well (where the business objects are struct-like enough that it doesn't matter) and just lived with the boilerplate. But I see little advantage in this over just having a dictionary that I can inspect to initialise my real business object. True that is not strongly-typed, but the stage between the message-object and the business object can have validation errors anyway, so why not treat typechecking as part of that?