简体   繁体   English

jaxb上下文中的package-info.class内容

[英]package-info.class content in jaxb context

Heyho, Heyho,

i'm currently having problems with the JAXB serialization process. 我目前遇到了JAXB序列化过程的问题。 jaxb version 2, used for serialization properties. jaxb版本2,用于序列化属性。

Is it possible to add multiple package level annotations in "package-info.class"? 是否可以在“package-info.class”中添加多个包级别注释? Currently i'm creating this file manually, there's already one "adapter entry" in it and it has to stay there. 目前我手动创建这个文件,其中已经有一个“适配器条目”,它必须留在那里。 Although i'm searching like an idiot, every example is with just one entry, but i guess that's just not possible, because the semantic should be more flexible, allowing multiple package level annotations than just one. 虽然我正在寻找一个白痴,但每个例子只有一个条目,但我想这是不可能的,因为语义应该更灵活,允许多个包级别注释而不仅仅是一个。

The problem is, that i'm using a @XmlJavaTypeAdapter(AdapterForMap.class) on every map-member in a class, but the map actually contains another type (as value), let's say Font, which needs to have a appropriate xml adapter. 问题是,我在类中的每个map成员上使用@XmlJavaTypeAdapter(AdapterForMap.class),但是地图实际上包含另一种类型(作为值),比如说Font,它需要有一个合适的xml适配器。 At the moment i'm not able to use this Font-Adapter-like, because 'package-info.class' already has one entry. 目前我无法使用类似Font-Adapter,因为'package-info.class'已经有一个条目。

thanks in advance! 提前致谢! :) :)

The @XmlJavaTypeAdapters can be used at the package level to register many instances of @XmlJavaTypeAdapter . 可以在包级别使用@XmlJavaTypeAdapters来注册@XmlJavaTypeAdapter许多实例。

package-info 包信息

@XmlJavaTypeAdapters({
    @XmlJavaTypeAdapter(type=DateTime.class, value=DateTimeAdapter.class),
    @XmlJavaTypeAdapter(type=DateMidnight.class, value=DateMidnightAdapter.class),
    @XmlJavaTypeAdapter(type=LocalDate.class, value=LocalDateAdapter.class),
    @XmlJavaTypeAdapter(type=LocalTime.class, value=LocalTimeAdapter.class),
    @XmlJavaTypeAdapter(type=LocalDateTime.class, value=LocalDateTimeAdapter.class)
})
package blog.jodatime;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;    
import org.joda.time.*;

For a Complete Example 完整的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM