Код: Выделить всё
public class MyDataObj {
private int a;
public static MyDataObj valueOf(String jsonStr) {
return new MyDataObj(new ObjectMapper().readTree(jsonStr).get("a").asInt());
}
public MyDataObj(int a) { this.a = a; }
public int getA() { return a; }
}
Код: Выделить всё
@POST
@Path("/myService")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response myService(MyDataObj serviceBody) {
String msg = doSomethingMeaningfulWith(serviceBody.getA());
return Response.ok().entity("{ \"result\": \"" + msg + "\" }");
}
Код: Выделить всё
org.eclipse.persistence.exceptions.JAXBException Exception Description: The class MyDataObj requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.Но статический метод "valueOf" не будет вызываться в приведенном выше примере.
Теперь вопрос: как я могу зарегистрировать " фабричный метод» где-то будет создавать объект? Или есть какой-то альтернативный способ?
Подробнее здесь: https://stackoverflow.com/questions/790 ... -rest-requ
Мобильная версия