我正在使用 Jboss Resteasy 和 Jackson 将响应编组到对象中。问题是我要连接的 API 如果出错则返回 A 类型的单个对象,如果成功则返回 B 类型的对象列表。我的目标是拥有一个像下面这样的对象 C:
class C {
A a;
List<B> bList;
}
但是,当我尝试这个时,我得到了(在它返回成功的情况下)
Caused by: org.codehaus.jackson.map.JsonMappingException: Failed to narrow content type [collection type; class java.util.List, contains [simple type, class com.B]] with content-type annotation (com.C): Class com.C is not assignable to com.B
at org.codehaus.jackson.map.deser.BasicDeserializerFactory.modifyTypeByAnnotation(BasicDeserializerFactory.java:797)
at org.codehaus.jackson.map.deser.BeanDeserializerFactory.constructSettableProperty(BeanDeserializerFactory.java:1375)
at org.codehaus.jackson.map.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:1182)
at org.codehaus.jackson.map.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:707)
我只是不确定我需要什么样的 @Json 注释(或者即使可能)