简体   繁体   English

使用JAXB编组到现有对象

[英]Marshalling to an existing object using JAXB

Is it possible to marshal XML directly onto an existing object and have only specific fields updated? 是否可以将XML直接封送到现有对象上并仅更新特定字段?

I would like to only modify certain fields that are requested by the client. 我只想修改客户端请求的某些字段。

Any pointers ? 有什么指针吗?

The solution is : Annotations and Reflection. 解决方案是: 注释和反思。 and no there are no libraries for the same. 并且没有相同的库。 I searched a lot when I was doing this task. 我在做这项任务时经常搜索。

I have done exactly the same thing as you want, I have done my own implementation for this. 我已经做了你想要的完全相同的事情,我已经完成了我自己的实现。 But it is proprietary so I cannot share. 但它是专有的,所以我无法分享。

But to hint you on solution: I have used annotations to mark the fields that are Reloadable and then used Reflection to reload only the parts that are reloadable. 但是要提示你解决方案:我使用注释标记可重新加载的字段,然后使用Reflection重新加载可重新加载的部分。

Step 1: Again unmarshal the xml to create a new Object 步骤1:再次解组xml以创建新的Object

Step 2: Call the setter methods on the old object with the new values from the newly unmarshalled object. 步骤2:使用新解组对象中的新值调用旧对象上的setter方法。

Hope this helps. 希望这可以帮助。

The short answer is no. 最简洁的答案是不。 There is no easy way to customize the jaxb bindings thinking of a generic solution. 没有简单的方法来定制思考通用解决方案的jaxb绑定。 See JAXB and class instantiation 请参阅JAXB和类实例化

Another solution (maybe cruder) would be to extract the XML part you want to process and then execute the unmarshall. 另一个解决方案(可能更粗糙)是提取您要处理的XML部分,然后执行unmarshall。 See Java How to extract a complete XML block 请参阅Java如何提取完整的XML块

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

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