English 中文(简体)
多个客户需要不同的日本航天中心说明
原标题:Multiple clients require different JAXB annotations
  • 时间:2012-01-12 16:11:14
  •  标签:
  • java
  • jaxb

我有一个可以由多个客户消费的班子(即德国马克、外部系统等)。

@XmlRootElement
class A {
    String field = "Hello World";

    public String getField() {
       return field;
    }
}

对于一名客户来说,我不想把由此而产生的XML列入这一类别的所有细节,因此,我要把细节与XmlTransient混在一起。

@XmlRootElement
class A {
    String field = "Hello World";

    @XmlTransient
    public String getField() {
       return field;
    }
}

问题在于,其他客户需要看到这一数据,现在它隐藏起来。

在我有两个客户想要几乎相同数据的情况下,我如何满足这一要求? 我通过扩大A和适当宣传以满足每个客户的需要来完成这项工作:

@XmlRootElement
class B extends A {
    @XmlTransient
    public String getField() {
       return super.getField();
    }
}

@XmlRootElement
class C extends A {
    public String getField() {
       return super.getField();
    }
}

这一工作似乎很麻烦。 是否有其他办法这样做? 我确信,在我已经表明的情况下,我可以使用XmlJavaAdapter,但在我的实际生活法典中,我所提到的数据可能是复合物体的一部分,XmlJavaAdapter似乎不合适。

希望一切都有意义!

问题回答

<>说明: I m the EclipseLink JAXB (MOXy) http://jcp.org/en/jsr/detail?id=222“rel=“nofollow noreferer”>JAXB(JSR-222)。

@skaffman所述,您可使用MOXy推广器来完成这一用途。 混合氧化物能够代表XML的绘图元数据。 这意味着,你可以提供一张地图,作为说明,并补充XML地图。

以下是谷歌和雅虎天气服务结果的单一物体模型的链接:

The code that corresponds to this example is also available on GitHub:

我猜测MOXy不是免费的(如果我错了的话,我就错了)。

My free solution is to use an extra "version" field in the JAXB object to distinguish multiple versions of bindings. Usually, I use enum as its type, i.e., enum Version {V1, V2, ...};

因此,就原来的例子而言,我把“现场”方法定义为“现场”方法。

@XmlElement
public String getField() {
    if (version == Version.V1) {
        return field;
    } else if (version == Version.V2) {
        return null; // hidden
    }

}

对于客户1,我将确定版本的价值。 V1, 接着是瓦 Java的物体;对客户2来说,我将把版本的数值改为版本v2, 然后再进行装饰。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签