@Path("persons")
public class PersonResource {
private final PersonRepository repository;
public PersonResource() {
this(null);
}
@Inject
public PersonResource(PersonRepository repository) {
this.repository = repository;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
public Person getPerson(@PathParam("id") String id) {
return repository.findById(id);
}
}
@Dependent
does
@mdagit you may need to specify the content type in your response - something like:requestContext.abortWith(Response.status(Status.FORBIDDEN).entity(Entity.entity(Map.of("error", err), MediaType.APPLICATION_JSON)).build());
orrequestContext.abortWith(Response.status(Status.FORBIDDEN).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).entity(Map.of("error", err)).build());
I'm just randomly guessing at the content type you want - but ultimately, that's the issue - the runtime doesn't know what to serialize the map to.
type(...)
method on the ResponseBuilder
class that might be cleaner than the snippets I first suggested. ex: