mardi 3 mars 2015

How to ignore an unknown class when using RestTemplate

I'm using Spring RestTemplate to retrieve informations from a rest server. The call is as follow:



SyncInfo[] result = restTemplate.getForObject(url, SyncInfo[].class, param1, param2);


SyncInfo is a parent class, with lots of childrens, let's call them



ClassA extends SyncInfo
ClassB extends SyncInfo
ClassC extends SyncInfo


It works very well.


My problem is that sometimes, the server is updated with new kind of object. For example, it could return a list with a ClassD which also extends SyncInfo.


My program doesn't know what is a ClassD object and the call fails.


Is there a way to tell the RestTemplate object to ignore unknown class? Just deserialize the one you can and ignore the others?


Because the only other way is to create the class in my code so it will be able to deserialize it but it's kind of dirty because my code don't need this class and it creates a dependency between my code and the server, which I don't like.


Aucun commentaire:

Enregistrer un commentaire