MessageBodyWriter not found for media type=application/json when returning JSON in REST web service with Jersey

后端 未结 5 1603
难免孤独
难免孤独 2020-12-19 16:20

I am trying to create a very simple REST service using Jersey. Here is the service code

@Path(\"/UserService\")
publ         


        
5条回答
  •  轮回少年
    2020-12-19 16:36

    Your xml was working so I assume that you have @XmlRootElement annotation in your User class.

    The thing is, it knows how to convert it to xml with the annotation @XmlRootElement but it doesn't know how to convert it to JSON.

    So for making it convert everything to JSON with the same annotation of xml(ie @XmlRootElement) we can add

    jersey-media-moxy-.jar

    or for maven users

    
        org.glassfish.jersey.media
        jersey-media-moxy
    
    

    Also it should have a no argument constructor

提交回复
热议问题