Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all properties java Object

Tags:

java

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).

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

@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.

Sorry for my english im from spain xD

Thanks for all!!

like image 386
Antonio Sánchez Avatar asked Feb 03 '15 10:02

Antonio Sánchez


1 Answers

You can use:

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

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

like image 62
roeygol Avatar answered Sep 22 '22 10:09

roeygol