ProvidenceMessageBodyWriter implements MessageBodyWriter<PMessage> { @Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (!PMessage.class.isAssignableFrom(type) || MediaType.WILDCARD_TYPE.equals(mediaType)) { return false; } try { provider.getSerializer(mediaType.toString()); return true; } catch (Exception e) { return false; } } protected  ProvidenceMessageBodyWriter(@Nonnull SerializerProvider provider); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(PMessage t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override @SuppressWarnings("unchecked") void writeTo(PMessage entity,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream);  }
@Test @SuppressWarnings("unchecked") public void testIsWritable() { ProvidenceMessageBodyWriter reader = new DefaultProvidenceMessageBodyWriter(); Annotation[] annotations = new Annotation[0]; assertTrue(reader.isWriteable(Operand.class, null, annotations, MediaType.valueOf(JsonSerializer.MEDIA_TYPE))); assertTrue(reader.isWriteable(Operand.class, null, annotations, MediaType.valueOf(JsonSerializer.JSON_MEDIA_TYPE + "; encoding=utf-8"))); assertTrue(reader.isWriteable(Operand.class, null, annotations, MediaType.valueOf(BinarySerializer.MEDIA_TYPE))); assertTrue(reader.isWriteable(Operand.class, null, annotations, MediaType.valueOf(BinarySerializer.ALT_MEDIA_TYPE))); assertFalse(reader.isWriteable(PMap.class, null, annotations, MediaType.valueOf(BinarySerializer.MEDIA_TYPE))); assertFalse(reader.isWriteable(String.class, null, annotations, MediaType.valueOf(BinarySerializer.ALT_MEDIA_TYPE))); assertFalse(reader.isWriteable(Operand.class, null, annotations, MediaType.WILDCARD_TYPE)); assertFalse(reader.isWriteable(Operand.class, null, annotations, MediaType.TEXT_PLAIN_TYPE)); }