Skip to content

Instantly share code, notes, and snippets.

@deltastateonline
Created October 9, 2019 10:05
Show Gist options
  • Save deltastateonline/8e76f3d4bd239b0c007ee0d6de563c03 to your computer and use it in GitHub Desktop.
Save deltastateonline/8e76f3d4bd239b0c007ee0d6de563c03 to your computer and use it in GitHub Desktop.
Creating annotation for an array of object
package com.adjustit.employeeapi.model;
import java.io.Serializable;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Employee implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String firstname;
private String lastname;
private String emailaddress;
private int age;
private double salary;
private ArrayList<EmployeeDoc> employeeDocuments;
public Employee(int id, String firstname, String lastname, String emailaddress, int age, double salary) {
super();
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
this.emailaddress = emailaddress;
this.age = age;
this.salary = salary;
}
public Employee() {
// TODO Auto-generated constructor stub
}
@XmlElement(name = "employeeId")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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 String getEmailaddress() {
return emailaddress;
}
public void setEmailaddress(String emailaddress) {
this.emailaddress = emailaddress;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public String toString() {
return "Employee {id=" + id + ", firstname=" + firstname + ", lastname=" + lastname + ", emailaddress="
+ emailaddress + ", age=" + age + ", salary=" + salary + "}";
}
@XmlElementWrapper(name = "employeeDocuments")
@XmlElement(name = "employeedoc")
public ArrayList<EmployeeDoc> getEmployeeDocuments() {
return employeeDocuments;
}
public void setEmployeeDocuments(ArrayList<EmployeeDoc> employeeDocuments) {
this.employeeDocuments = employeeDocuments;
}
}
@deltastateonline
Copy link
Author

Most examples apply the annotation on the field properties, because they have no getter for the collection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment