简体   繁体   English

JAXB忽略package-info.java中的@XmlAccessorFactory

[英]JAXB ignores @XmlAccessorFactory in package-info.java

We have written our own AccessorFactory to serialize our POJO in XML, so we have created package-info.java and added the annotation @XmlAccessorFactory in this file. 我们已经编写了自己的AccessorFactory来以XML序列化POJO,因此我们创建了package-info.java并在该文件中添加了注释@XmlAccessorFactory。

@XmlAccessorFactory(MeiAccessorFactory.class)
package com.meicpg.ti.domain;

All our POJO are annotated with @XmlAccessorType(XmlAccessType.NONE), and we have annotated all fields that have to be serialized with @XmlElement 我们所有的POJO都使用@XmlAccessorType(XmlAccessType.NONE)进行了注释,并且我们已经注释了必须使用@XmlElement序列化的所有字段。

Most of the time the serialization works well, but sometimes on dev's machine (in production we don't have this issue, and developer who works on Unix ) POJO aren't serialized. 在大多数情况下,序列化都能很好地进行,但是有时在开发人员的机器上(在生产中我们不会遇到这个问题,而在Unix上工作的开发人员)POJO不会序列化。

I have tried to annotate one of the POJO with @XmlAccessorFactory, and it has been serialized correctly. 我尝试使用@XmlAccessorFactory注释POJO之一,并且它已正确序列化。 On another POJO, I moved @XmlElement annotations on getters and it has been serialized correctly too. 在另一个POJO上,我将@XmlElement注释移到了getter上,并且它也已正确序列化。

Before to apply one of this solution on all my POJO, I would like to know if somebody has already met this weird behaviour and found why annotations in package-info.java are ignored. 在将这种解决方案之一应用于我的所有POJO之前,我想知道是否有人已经遇到这种怪异的行为,并且发现为什么package-info.java中的注释会被忽略。

Thanks. 谢谢。

I tried to add other annotations in package-info.java (like @XmlAccessorType(XmlAccessType.NONE) because we use it in every POJO), and it seems that all annotations in package-info is ignored. 我试图在package-info.java中添加其他注释(如@XmlAccessorType(XmlAccessType.NONE),因为我们在每个POJO中都使用了它),并且似乎package-info中的所有注释都被忽略了。 Any idea? 任何想法?

If annotations in package-info are being ignored be sure of the following: 如果忽略package-info中的注释,请确保以下内容:

  1. Your package annotations are defined in a file called package-info.java . 包批注在名为package-info.java的文件中定义。
  2. Your package-info.java source file is being compiled into package-info.class . 您的package-info.java源文件正在被编译为package-info.class
  3. The package-info annotations will only apply to classes within that package. package-info批注仅适用于该包中的类。 You will not see them impact classes in other packages so you may need other package-info classes. 您不会看到它们影响其他软件包中的类,因此您可能需要其他package-info类。

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

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