JAXB对象 - 哈希码和等号 [英] JAXB objects - hashcode and equals

查看:138
本文介绍了JAXB对象 - 哈希码和等号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个巨大的Java应用程序,它完全基于JAXB序列化。中间件服务器完成所有数据库访问并发送JAXB对象中的所有数据对象并序列化为XML并将数据发送到UI(C#.Net)。 / p>

数据从db访问到JAXB java对象的大部分时间后,我将不得不进行一些处理,比如根据属性对对象集合进行排序,找到平均值,对集合中的对象列表进行一些计算等。



我的主要问题是,JAXB对象没有equals和hashcode。所以我正在做的是将所有数据移动到一些用户定义的数据对象,其中我有hashcode,equals,compareTo定义,所以我可以在集合中执行所有操作,然后复制到JAXB对象。我认为这是一个额外的开销。



问题:



1)jaxb对象是否支持equals / hashcode / compareTo - 我可以在模式中指定这些吗?



2)还有其他更好的选择吗?



谢谢。

解决方案

不幸的是,jaxb没有提供开箱即用的功能。你可以使用这个插件,或者自己编写更多可自定义的行为。


We have a huge java application that entirely works based on JAXB serialization.The middleware server does all db access and sends all the data Objects in JAXB objects and serializes to XML and sends the data to UI ( C#.Net).

Most of the times after the data is populated from db access into the JAXB java objects , I will have to some processing like "sort the collection of objects based on attribute" , find the avg , do some calculation on the list of objects in the collection etc.

My major problem is, JAXB objects don't have equals and hashcode. So what I am doing is moving all the data to some user defined Data objects where I have hashcode, equals, compareTo defined so I can do all operations in the collections and then copy to the JAXB objects. I think this is a extra overhead.

Questions:

1) does jaxb objects support equals /hashcode/ compareTo - can I specifiy these in schema?

2) Any other better alternatives?

Thanks.

解决方案

unfortunately, jaxb does not provide this out of the box. you can use this plugin, or write your own for more customizable behavior.

这篇关于JAXB对象 - 哈希码和等号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆