我重寫MessageBodyWriter
的WriteTo
方法:如何在澤西的MessageBodyWriter的writeTo方法中獲取anotations值?
@Override
public void writeTo(Detail detail, Class<?> type, Type genericType, Annotation[] annotation, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
}
有一個annotation
參數。其實我想從中取view
註釋,以便我可以根據view
返回Detail
數據。
這裏是我的WriteTo
代碼:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.DEFAULT_VIEW_INCLUSION, false);
mapper.writerWithView(JSONView.CustomerView.class).writeValue(entityStream, detail);
其實,我想從註釋獲取視圖名稱,這樣我就可以根據視圖返回的具體數據。
如何從anotation中獲取view
類名?
這裏是我的資源代碼:
@POST
@Produces({MediaType.APPLICATION_JSON})
@Path("testDetail")
@JsonView(JSONView.TicketView.class)
public TestDetail testDetail()
{
TestDetail testDetail = new TestDetail();
return testDetail;
}
它不工作,任何其他解決方案? – unknownbits
對不起,你想要的方法,我會更新代碼。 – Deceiver
在哪個包中的方法是?? – unknownbits