【发布时间】:2017-11-23 15:39:53
【问题描述】:
我想在下面的杰克逊反序列化中添加多个类。但我该怎么做?下面是示例代码。
XmlMapper mapper = new XmlMapper();
JaxbAnnotationModule module = new JaxbAnnotationModule();
mapper.registerModule(module);
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
mapper.setAnnotationIntrospector(introspector);
TypeFactory typeFactory = mapper.getTypeFactory();
Class<? extends Collection> list;
MapType mapType = typeFactory.constructRawCollectionType(list);
File is = new File("myXMLFile.xml");
ArtworkContentMessageType je = mapper.readValue(is,mapType);
下面的部分让我感到困惑。如何将类添加到列表中?
Class<? extends Collection> list;
MapType mapType = typeFactory.constructRawCollectionType(list);
如何添加多个类(例如:Body.class 和 P.class)。我在下面尝试,它不是正确的对象,因为它不是 Class 类型。
List<Class> clazz = new ArrayList<>();
clazz.add(ArtworkContentMessageType.class);
clazz.add(Body.class);
clazz.add(P.class);
MapType mapType = typeFactory.constructRawCollectionType(clazz);
【问题讨论】:
-
不确定你在问什么。是关于 List
还是关于 Class ?? -
@ChrisNeve 关于类类型。