Hi,
I am facing a problem where jsonb adapter is not invoked.
Here is a simplified case.
jaxrs application
---------------------------
@ApplicationPath("/app")
public class App extends Application{
}
adapter
------------------------
public class B implements JsonbAdapter<Book, JsonObject> {
@Override
public JsonObject adaptToJson(Book obj) throws Exception {
return Json.createObjectBuilder()
.add("customfield", obj.getId() + " " + obj.getTitle())
.build();
}
@Override
public Book adaptFromJson(JsonObject obj) throws Exception {
throw new UnsupportedOperationException("Not supported yet.");
//To change body of generated methods, choose Tools | Templates.
}
}
dto
------------------------
public class Book {
private int id;
private String title;
public Book() {
}
public Book(int id, String title) {
this.id = id;
this.title = title;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
resource
-----------------------
@Path("/r")
public class R {
@GET
@Produces({MediaType.APPLICATION_JSON})
public Response response() {
Book book = new Book(100, "Apache Tomee");
JsonbConfig config = new JsonbConfig()
.withFormatting(true)
.withAdapters(new B());
Jsonb jsonb = JsonbBuilder.create(config);
String toJson = jsonb.toJson(book);
return Response.ok(toJson).build();
}
}
What am i missing?
Thanks.