java中使用反射查找复合类的所有属性

发布于 2024-12-17 20:25:42 字数 161 浏览 2 评论 0原文

我有一个要求,我将获得一个对象,并且我必须准备该对象中所有属性的列表。该对象可以是复合对象。这个想法是获取 String、Integer、boolean 和 Date 类型的所有属性的列表。有一种方法可以使用反射机制并递归地执行此操作。然而,这可能会变得相当复杂。所以我只是想知道是否有任何第三方库可以使用。

I have requirement where in I will be given an object and I have to prepare a list of all the attributes in that object. The object can be a composite object. The idea is to get the list of all the attributes of type String, Integer, boolean and Date. There is a way to use reflection mechanism and doing this recursively. However, this can become quite complex. So I was just wondering, if there is any third party library that I can use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2024-12-24 20:25:42

尝试查看 Apache BeanUtils。特别是 PropertyUtils .getPropertyDescriptors()。警告,这仅适用于具有 getter 和 setter 的字段。

然后,您必须为在父类中找到的每个属性描述符递归地调用它。

Try looking at Apache BeanUtils. In particular PropertyUtils.getPropertyDescriptors(). Caveat, this only works for fields with getters and setters.

You'd then have to call this recursively for each property descriptor you find in the parent class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文