Jersey client can not deserializable json services - exception(can not deserialize instance)

前端 未结 1 469
礼貌的吻别
礼貌的吻别 2021-01-24 23:13

JSON response:

{
    "categories": [{
            "id": "1",
            "category": "category1"         


        
相关标签:
1条回答
  • 2021-01-25 00:12

    Brate, slusaj... I had the same problem. I was building a simple Restful service and JAXB was returning JSON from my JaxB annotated POJO class when GET methods were executed quite well. When my methds were @Consuming JSON (POST, PUT cases) I found out that JAXB had some problems there.

    It's better to use JACKSON instead JaxB annotations (you'll find a lot about it googling) when buiilding Jersey / JSON service. The thing is that JAXB doesn't do well the conversion (deserialization) from JSON to your POJO objects. JAXB with its @XMLRootElement is quite suitable when working with XML, but not JSON.

    This is what I have in web.xml to enable Jackson's deserialization/serialization of JSON:

    <!--  JAXB works great with XML but with JSON it's much better to use Jackson. Jersey will use Jackson -->
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
    

    Google for .jar file that needs to be included for Jersey to use Jackson... Good luck...

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