lundi 18 janvier 2016

Implement HttpMessageConverter which handle both Json and List

I am trying to implement a HttpMessageConverter which handle JSON, like MappingJackson2HttpMessageConverter. I am able to handle 1 JSON object, both read and write, but if the service (REST service in Controller) returns a List<>, how do I recognize that it is a List with object that my converter could support? my converter source code

I think if my canRead() canWrite() methods return true for both DBObject and List<DBObject>, then my converter could handle both situation. but after I tried some reflection methods, I could get the type is ArrayList<T>. I still do not know how to determine that what the actually type of its element. From related question, seems like java could not know what actually type is at runtime, but it is possible from a method which I still don't understand. The MappingJackson2HttpMessageConverter seems to support this, looking at the source code, it is like ObjectMapper is related, but the code is too complicated for me to understand.

How should I modify my converter to support List<DBObject>?





Aucun commentaire:

Enregistrer un commentaire