JSON to Java Objects, best practice for modeling the json stream

后端 未结 3 1351
心在旅途
心在旅途 2021-01-20 17:58

I have a JSON stream being generated by a server side C++ program that is currently in development. I\'ve been given a sample of the resulting JSON and I am concerned that I

3条回答
  •  礼貌的吻别
    2021-01-20 18:31

    I'd be more concerned with what looks like metadata fields in the data stream. The top level 'abort' and 'more' attributes look like some kind of structured string which you may have to parse? Aside from that, you just need to model each Java object with the widest possible set of fields that will be sent from your external program. You don't have to worry if transmitted data has one or more of the fields missing, most JSON libraries will just deserialize a null in that case. Also, most of the JSON libraries will also allow you to specify that you want to ignore unknown incoming fields.

    So between deserializing null for missing fields and ignoring extra fields, you should be good to go for your parse.

提交回复
热议问题