Ошибка JAXB при использовании в SpringREST для возврата ArrayList объекта домена - PullRequest
0 голосов
/ 10 декабря 2011

Я пытаюсь использовать JAXB в Spring RESTful webservice.Мой код выглядит следующим образом:

 @RequestMapping(value = "/countries",
        method = RequestMethod.GET,
        headers="Accept=application/xml, application/json")
 public @ResponseBody CountryList getCountry() {
  logger.debug("Provider has received request to get all persons");

  // Call service here
  CountryList result = new CountryList();
  result.setData(countryService.getAll());

  return result;
 }

Класс CountryList.java выглядит следующим образом:

@XmlRootElement(name="countries")
public class CountryList {

 @XmlElement(required = true)
 public List<Country> data;

 @XmlElement(required = false)
 public List<Country> getData() {
  return data;
 }

 public void setData(List<Country> data) {
  this.data = data;
 }
}

Country.java выглядит следующим образом:

@XmlRootElement(name="country")
public class Country {

    private Calendar createdDt;
    private String updatedBy;
    private String createdBy;
    private Long id;
    private String countryName;
    private Calendar updatedDt;

// getters and setters for all attributes goes here 

}

Теперь,когда я получаю доступ к методу getCountry (), я получаю следующее исключение

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "data"
    this problem is related to the following location:
        at public java.util.List com.cisco.bic.services.model.CountryList.getData()
        at com.cisco.bic.services.model.CountryList
    this problem is related to the following location:
        at public java.util.List com.cisco.bic.services.model.CountryList.data
        at com.cisco.bic.services.model.CountryList

Кто-нибудь знает, почему возникает эта ошибка.Я делаю что-то не так в аннотирующей части ??

Пожалуйста, помогите.

С уважением Сарой

1 Ответ

0 голосов
/ 11 декабря 2011

Вы не можете комментировать как получатель / установщик, так и поле, вам нужно выбрать один из них.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...