拥有一个具有大量属性的类,默认情况下Jaxb将Unanotated属性视为XmlElement,
如何强制它将所有Unanotated属性编码为XmlAttribute?
使用JAXB RI,您可以实现自定义注释阅读器并使用JAXB RI上下文进行配置:
final AnnotationReader<Type, Class, Field, Method> annotationReader = new CustomAnnotationReader(); final Map<String, Object> properties = new HashMap<String, Object>(); properties.put(JAXBRIContext.ANNOTATION_READER, annotationReader); final JAXBContext context = JAXBContext.newInstance( "org.jvnet.annox.samples.po", Thread.currentThread().getContextClassLoader(), properties); final Object myObject = context.createUnmarshaller().unmarshal( ... );
使用MOXy,您可以使用XML bindings为您的属性配置所需的mappin .
我认为自定义注释阅读器的工作量会减少 .
1 回答
使用JAXB RI,您可以实现自定义注释阅读器并使用JAXB RI上下文进行配置:
使用MOXy,您可以使用XML bindings为您的属性配置所需的mappin .
我认为自定义注释阅读器的工作量会减少 .