BAEL-3212 - Examples of POJO, Bean and BeanUtils reflection (#7782)
* BAEL-3212 - Examples of POJO, Bean and BeanUtils reflection * Update pom.xml
This commit is contained in:
parent
0451f008be
commit
65b94b66f4
|
@ -15,10 +15,10 @@
|
|||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
|
@ -29,6 +29,11 @@
|
|||
<artifactId>jmh-generator-bytecode</artifactId>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.baeldung.pojo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class EmployeeBean implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3760445487636086034L;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private LocalDate startDate;
|
||||
|
||||
public EmployeeBean() {
|
||||
|
||||
}
|
||||
|
||||
public EmployeeBean(String firstName, String lastName, LocalDate startDate) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public LocalDate getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(LocalDate startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.baeldung.pojo;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class EmployeePojo {
|
||||
|
||||
public String firstName;
|
||||
|
||||
public String lastName;
|
||||
|
||||
private LocalDate startDate;
|
||||
|
||||
public EmployeePojo(String firstName, String lastName, LocalDate startDate) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return this.firstName + " " + this.lastName;
|
||||
}
|
||||
|
||||
public LocalDate getStart() {
|
||||
return this.startDate;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.pojo;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
|
||||
|
||||
public class ReflectionExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("Fields for EmployeePojo are:");
|
||||
for (PropertyDescriptor pd : PropertyUtils.getPropertyDescriptors(EmployeePojo.class)) {
|
||||
System.out.println(pd.getDisplayName());
|
||||
}
|
||||
|
||||
System.out.println("Fields for EmployeeBean are:");
|
||||
for (PropertyDescriptor pd : PropertyUtils.getPropertyDescriptors(EmployeeBean.class)) {
|
||||
System.out.println(pd.getDisplayName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue