简体   繁体   English

将字段解编为枚举-可能吗?

[英]Unmarshall field to an Enum - possible?

I have an xml document that holds a list of Car objects. 我有一个XML文档,其中包含Car对象的列表。 Inside each Car object, it has elements Owner and Mechanic. 在每个Car对象中,它具有元素Owner和Mechanic。 Both Owner and Mechanic have exactly the same fields (Name and postcode). 所有者和技工具有完全相同的字段(名称和邮政编码)。 I want to unmarshal the Car objects into a list of Cars. 我想将“汽车”对象编组为“汽车”列表。 Instead of having 2 sub-objects called Owner and Mechanic, I'd like to create one called Person. 我没有创建两个名为“所有者”和“机械师”的子对象,而是创建了一个名为“人”的对象。 Inside person I'd like to indicate what type of person they are, either Owner or Mechanic. 内部人员我想指出他们是什么类型的人员,所有者或技工。 I created an Enum called PersonType holding Owner and Mechanic. 我创建了一个名为PersonType的枚举,其中包含所有者和机械师。 Inside Car, I have put a variable called PersonType to differentiate. 在Car内,我放置了一个名为PersonType的变量以进行区分。 The PersonType is always null. PersonType始终为null。

Can any help me to achieve this goal? 有什么可以帮助我实现这一目标的吗? I really think 2 objects for Owner and Mechanic is unnecessary. 我真的认为Owner和Mechanic不需要2个对象。

我使用了Eclipse MOXy的@XmlPath属性,它可以正常工作。

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

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