REST API - Use the “Accept: application/json” HTTP Header

后端 未结 4 1210
抹茶落季
抹茶落季 2020-12-08 10:08

When I make a request, I get a response in XML, but what I need is JSON. In the doc it is stated in order to get a JSON in return: Use the Accept: application/json

4条回答
  •  醉梦人生
    2020-12-08 10:12

    Well Curl could be a better option for json representation but in that case it would be difficult to understand the structure of json because its in command line. if you want to get your json on browser you simply remove all the XML Annotations like -

    @XmlRootElement(name="person")
    @XmlAccessorType(XmlAccessType.NONE)
    @XmlAttribute
    @XmlElement
    

    from your model class and than run the same url, you have used for xml representation.

    Make sure that you have jacson-databind dependency in your pom.xml

    
      com.fasterxml.jackson.core
      jackson-databind
      2.4.1
    
    

提交回复
热议问题