I have a CustomerEntiy with getter and setter the sample customerEntity is
customerEntity =
{
"customerNumber": "1234",
"firstName": "Test",
"email": "[email protected]",
"id": "1",
"middleName": "doe",
"phone": "11111"
}
I have java class Attributes of JsonProperty with getter and Setters as below
Attributes =
{
"name": "string"
"value": "string"
}
I have a list which will contains random elements from CustomerEntiy for example:
List<String> stringlist = { "firstName" , "phone"}
I have created an List of type Attributes
List<Attributes> Attributeslist = new ArrayList<>();
I want to create Attributelist of all the elements in stringlist for Example here it would be:
Attributeslist =[
{
"name": "firstName"
"value": "Test"
},
{
"name": "phone"
"value": "11111"
}
]
For this i have written the code as below but what to pass in previewattributes.setValue(); because that value would depends on what is mystring in below for loop. In this example it would be previewattributes.setValue(customerEntity.getFirstName()); and previewattributes.setValue(customerEntity.getPhone()); for different iteration but how do i code it??
for (String mystring : stringlist) {
Attributes previewattributes;
previewattributes = new Attributes();
previewattributes.setName(mystring);
previewattributes.setValue(value here would be of customerentity);
Attributeslist.add(previewattributes);
}
CustomerEntity:
@Entity
@Table(name = "Customer_tbl")
public class CustomerEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long rowId;
@Column(name = "customer_number")
private String customerNumber;
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
}