Ich habe eine Ressource mit einem Verfahren wie:Jersey: Kein geeigneter Konstruktor für Typen [einfache Art, Klasse Thing] gefunden: kann nicht von JSON-Objekt instanziiert
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/add")
public Response putThing(Thing thing) {
try {
//Do something with Thing object
return Response.status(HttpStatus.SC_OK).build();
} catch (Exception e) {
log.error("Request failed", e);
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build();
}
}
Thing:
public class Thing {
private final String symbol;
private final String name;
public Stock(String symbol, String name) {
this.symbol = symbol;
this.name = name;
}
public String getSymbol() {
return this.symbol;
}
public String getName() {
return this.name;
}
}
wenn ich eine PUT-Anfrage wie:
PUT /rest/add HTTP/1.1
Host: localhost:8135
Content-Type: application/json
Cache-Control: no-cache
{"symbol":"some symbol","name":"some name"}
ich die folgende Antwort erhalten:
Kein passender Konstruktor für Typ [einfache Art, Klasse Thing] gefunden: kann nicht von JSON-Objekt instanziiert (Standardkonstruktors oder Schöpfer fehlt, oder vielleicht müssen Typinformationen hinzufügen/aktivieren?)
Warum wird das JSON-Objekt von Jersey/Jackson nicht in mein POJO deserialisiert?
Mögliche Duplikate von [JsonMappingException: Es wurde kein geeigneter Konstruktor für den Typ \ gefunden [einfacher Typ, Klasse \]: kann nicht vom JSON-Objekt instanziiert werden] (https://stackoverflow.com/questions/7625783/jsonmappingexception-no-uitable- Konstruktor-gefunden-für-Typ-Simple-Type-Klasse) – Abhijeet