Posso inserire correttamente i dati XML nel mio servizio, ma, provando a fare lo stesso usando JSON, sto fallendo. Il POJO è:Come inoltrare la richiesta JSON a un servizio REST di Jersey?
@XmlRootElement
public class Address {
String city;
String zip;
//Getters & setters...
}
La risorsa servizio è:
@POST
@Produces("application/json")
public Address fix(Address a) {
return a;
}
Sto facendo un POST come segue:
POST /AcmeWeb/svc/simple HTTP/1.1
Content-Length: 30
Content-Type: application/json; charset=UTF-8
{"city":"Miami","zip":"33130"}
Il server risponde con un 400 Bad Request. Ho setacciato Internet ma non ho trovato alcun buon esempio di pubblicazione di JSON. Qualsiasi aiuto è apprezzato. Grazie.
Questo non ha aiutato. Ho anche aggiunto un'intestazione Accept: Accettare: application/json, text/javascript, */*; q = 0,01 – RajV
È strano, funziona per me. Ho aggiornato la mia risposta su come l'ho implementata. –
Controllare il log del server per vedere se c'è qualche traccia di stack sul lato server. –