jeudi 5 mars 2015

JSON conversion and app compatibility issues

I'm using Spring to manage communications between my Android client and a Java backend. In particular the class MappingJackson2HttpMessageConverter does the job of converting JSON to Java objects back and forth on Android.


My issue is the following: sometimes I need to update the app, which often results in additional fields to be added to some of the classes which build my model, and as a consequence additional fields in the JSON data that travels between the clients and my server. When I do that it would be crucial for the "old" versions of the app to remain compatible with the new, slightly enhanced, object model. In particular, if the server sends to the client a JSON payload with too many fields (compared to what the client "knows"), the client should just ignore those fields without complaining that it cannot create the object properly. Unfortunately this is not the case now, since if the server sends an additional field, say called "country", the client throws the following exception when trying to convert the object:



Could not read JSON: Unrecognized field "country" (class com.example.MyUser), not marked as ignorable (19 known properties: ...)


Thanks for any help!


Aucun commentaire:

Enregistrer un commentaire