Jersey: Kein passender Konstruktor für type gefunden [einfacher Typ, Klasse Thing]: kann nicht vom JSON-Objekt instanziiert werden

Habe ich eine Ressource mit einer Methode wie:

@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();
    }
}

Sache:

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"}

Bekomme ich die folgende Antwort:

Kein passender Konstruktor gefunden, geben Sie [einfache Art, Klasse Sache]: können
nicht instanziieren von JSON-Objekt (fehlende Standard-Konstruktor oder
Schöpfer, oder vielleicht hinzufügen/aktivieren geben Sie die Informationen?)

Warum ist Jersey/Jackson nicht Deserialisieren meine JSON-Objekt in mein POJO?

InformationsquelleAutor der Frage Edd | 2015-06-27

Schreibe einen Kommentar