나는 이상한 문제가 있습니다. @Provider를 사용하여 Mapper Exception을 주석 처리하고 작업을 정상적으로 처리하지만 아래 클래스에 주석을 달 때이 클래스를 사용하면 전혀 작동하지 않습니다.JBoss AS7 + RestEasy : @Provider를 사용하여 Custom MessageBodyReader를 활성화하는 방법이 없습니다.
@Consumes("application/x-java-serialized-object")
@Provider
public class JAXBSpecificMarshaller implements MessageBodyReader
{
@PersistenceContext(unitName = "primary", type = PersistenceContextType.EXTENDED)
private EntityManager em;
@Override
public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
return type.isAnnotationPresent(XmlRootElement.class);
}
@Override
public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException
{
try
{
// DataAdapter dataAdapter = new DataAdapter(em);
//unmarshaller.setAdapter(dataAdapter);
System.out.println(type.getName());
JAXBContext ctx = JAXBContext.newInstance(type);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
return unmarshaller.unmarshal(entityStream);
}
catch (JAXBException ex)
{
throw new RuntimeException(ex);
}
}
}
내 주된 이유는 특정 어댑터를 사용하여 해당 ID를 입력 XML에 전달하여 개체를 검색 할 수 있어야한다는 것입니다. 나는 이것을 따라 갔다 Serialize a JAXB object via its ID?. 하지만 내 enitymanger와 어댑터를 초기화하려면 그렇게하기 위해 MessageBodyReader를 사용해야한다고 들었다.
도움 주셔서 감사합니다.
'MessageBodyReader'가 배포 중이라는 것을 알고 있습니까? isReadable 메소드가 항상 false를 돌려주는 것이 가능한가? –
하지만 isReadable에서 항상 true를 보내더라도 작동하지 않습니다. 디버거를 사용하여 내가 deserialize 할 내 Entity 클래스 매개 변수화 된 형식이 아니므로 marshaller 그것을 사용하지 않는 및 CollectionProvider prefere 찾습니다. – Ghostwan