How to convert JSON to list of POJOs using RestEasy

前端 未结 1 1855
-上瘾入骨i
-上瘾入骨i 2021-01-25 02:23

I have to integrate our j2ee application with a REST webservice. And I wanted to use the RestEasy JAX-RS implementation from JBoss. The webservice returns an array in JSON forma

相关标签:
1条回答
  • 2021-01-25 02:27

    Provided that your JSON provider is capable of converting JSON to appropriate entities, then yes. The get method you call in the code has an overloaded version which accepts the class of entity to which the result is to be converted. Since there are problems with serializing certain collections' implementations, your type has to be wrapped in GenericType class, like that:

    List<Scheme> schema = [...].get(new GenericType<List<Scheme>>(){});
    

    The above method should work with just about every JAX-RS-compliant implementation.

    You can also use Jackson library, which allows you (amongst other things) to pass collections without need of wrapping them.

    0 讨论(0)
提交回复
热议问题