简体   繁体   中英

Unmarshall field to an Enum - possible?

I have an xml document that holds a list of Car objects. Inside each Car object, it has elements Owner and 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. Inside Car, I have put a variable called PersonType to differentiate. The PersonType is always null.

Can any help me to achieve this goal? I really think 2 objects for Owner and Mechanic is unnecessary.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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