获取所有属性 java 对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28296873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:21:11  来源:igfitidea点击:

Get all properties java Object

java

提问by Antonio Sánchez

I have an object in java that have a lot of properties. I want to get it for create a SOAP request dynamically (tags-value).

我在java中有一个对象,它有很多属性。我想用它来动态创建 SOAP 请求(标签值)。

I need all of this properties not only the first level (I want properties inside others properties).

我不仅需要第一级的所有这些属性(我想要其他属性中的属性)。

I see the reflection api in java in this web but only give me the public properties (or declared with getDeclaredFields()) of the object and I have properties in other classes because hibernate get me all values from a DB in FetchType.EAGER

我在这个网站上看到了 java 中的反射 api,但只给了我对象的公共属性(或用 getDeclaredFields() 声明),我在其他类中有属性,因为 hibernate 从 FetchType.EAGER 中的数据库中获取所有值

@Version
@Column(name = "VERSION")
private Integer version;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "ID_LUGAR")
public GatLugar gatLugar;

@Column(name = "NUM_ATESTADO")
public Long numAtestado;

@Temporal(TemporalType.DATE)
@Column(name = "FECHA_REGISTRO")
private Date fechaRegistro;

@Temporal(TemporalType.DATE)
@Column(name = "FECHA_HECHO")
private Date fechaHecho;

For example numAtestado with java reflection get it but gatLugar have more properties-values inside and dont have it with reflection.

例如 numAtestado 与 java 反射得到它,但 gatLugar 内部有更多的属性值,并且没有反射。

Sorry for my english im from spain xD

对不起,我的英语来自西班牙 xD

Thanks for all!!

谢谢大家!!

回答by roeygol

You can use:

您可以使用:

<YOUR CLASS>.getClass().getDeclaredFields()

And then also use: getDeclaredFields()for the field you got above

然后也使用:getDeclaredFields()对于你上面的领域