开发者

How to get values from enclosing elements in JAXB

开发者 https://www.devze.com 2023-04-03 15:43 出处:网络
I have the following XML structure: <PriceBook> <PriceList product=\"0D000000.007C.06\"> <Price .../>

I have the following XML structure:

<PriceBook>
    <PriceList product="0D000000.007C.06">
        <Price .../>
        <Price .../>
    </PriceList>
    ...
</PriceBook>

A PriceList holds a list of Price objects. I don't want that Price objects have back references to their PriceLists.

Question:

I would like to have the product information not only set in my PriceList objects, but also in the Price objects. Of course I don't want to have 开发者_运维问答that duplication in the XML itself, only on Java side. What is the most elegant way to do this?


You could leverage an afterUnmarshal event on the PriceList object. In this event you could iterate over the list of Price objects and set the product information. You would need to mark the product information on Price to be @XmlTransient.

For More Information

  • http://wiki.eclipse.org/EclipseLink/UserGuide/MOXy/Runtime/Events
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号