Reputation: 4073
Serializing an annotation with jersey always fails with an unknown error.
Minimal example is:
Jersey ressource
@TestAnno( id = "TestID" )
@Path( "/test" )
public class TestResource
{
@GET
@Produces( MediaType.APPLICATION_JSON )
public TestAnno list() throws JsonGenerationException, JsonMappingException, IOException
{
final TestAnno ta = getClass().getAnnotation( TestAnno.class );
return ta;
}
}
Annotation
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.TYPE )
public @interface TestAnno
{
@JsonProperty( "id" )
String id();
}
The call always returns
HTTP ERROR: 500
Problem accessing /schema. Reason:
Server Error
The debug log is empty, there are no exceptions or any other information about the error. What is the point where jersey fails?
Upvotes: 0
Views: 168
Reputation: 1448
Probably you don't have Serializer with such a class. Consider to write your Dto class and map all the information from your annotation to it. Then just return in as a response. Something like:
public Response list() throws JsonGenerationException, JsonMappingException, IOException
{
final TestAnno ta = getClass().getAnnotation( TestAnno.class );
MyDto dto = buildDto(ta);
return Response.ok(dto);
}
Upvotes: 1