java.util.목록 인터페이스를 포함 처리할 수 없습니다 인터페이스
-
08-07-2019 - |
문제
나는 듯하여 다음과 같은 제외하려고 할 때 배포하는 내용:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
java.util.List is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.util.List
at private java.util.List foobar.alkohol.register.webservice.jaxws.GetRelationsFromPersonResponse._return
at foobar.alkohol.register.webservice.jaxws.GetRelationsFromPersonResponse
java.util.List does not have a no-arg default constructor.
this problem is related to the following location:
at java.util.List
at private java.util.List foobar.alkohol.register.webservice.jaxws.GetRelationsFromPersonResponse._return
at foobar.alkohol.register.webservice.jaxws.GetRelationsFromPersonResponse
나의 코드가 작동이 잘 때까지 변경이 반환에서 유형 목록을 목록<List<RelationCanonical>>
여기에 부분적인 웹 서비스:
@Name("relationService")
@Stateless
@WebService(name = "RelationService", serviceName = "RelationService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class RelationService implements RelationServiceLocal {
private boolean login(String username, String password) {
Identity.instance().setUsername(username);
Identity.instance().setPassword(password);
Identity.instance().login();
return Identity.instance().isLoggedIn();
}
private boolean logout() {
Identity.instance().logout();
return !Identity.instance().isLoggedIn();
}
@WebMethod
public List<List<RelationCanonical>> getRelationsFromPerson(@WebParam(name = "username")
String username, @WebParam(name = "password")
String password, @WebParam(name = "foedselsnummer")
String... foedselsnummer) {
......
......
......
}
내가 노력했을 제거하여@SOAPBinding 하고 기본지만,같은 결과가 발생합니다.감사가 어떤 도움
업데이트
내가 원하는 참고 밖으로 무언가이다.나는 모든 목록을 ArrayList 며,그것은 컴파일합니다.내가 왜 이런 말 하는 이유 컴파일되고 일하지 않은 것으로 동작하기 때문에 이상합니다.나는 개체의 유형:RelationServiceStub.ArrayList 하지만 객체가 없을 얻는 방법 또는 작동하지 않으로 목록이다.도를 캐스팅 하는니다.
이 후에 나가 사용되는 축 2wsdl2java 그래서 지금 그것을 컴파일하고,그러나 나는 몰라요 어떻게 데이터를 얻을 수 있다.
해결책
에 대한 이해,당신은 할 수 없 프로세스는 일반 List
해를 포함,으로 포함 있는 아이디어가 어떻게 변환하는 것으로 XML.
대신,당신이 정의할 필요가 포함식 보유 List<RelationCanonical>
(나는 그것을 전화 Type1
고),또 다른 하나를 개최하 목록은 그러한 유형의 차례로(으로 다루고 있으로 List<List<...>>
;전화를 거는데 이 유형 Type2
).
결과는 다음 수 있습 XML ouput 다음과 같다:
<Type2 ...>
<Type1 ...>
<RelationCanonical ...> ... </RelationCanonical>
<RelationCanonical ...> ... </RelationCanonical>
...
</Type1>
<Type1>
<RelationCanonical ...> ... </RelationCanonical>
<RelationCanonical ...> ... </RelationCanonical>
...
</Type1>
...
</Type2>
지 않고 두 개의 바깥쪽 포함-주석 유형을 포함 프로세서 아무 생각이 없는 태그를 생성하고,따라서 실패합니다.
--편집:
내가 무슨 뜻인은 다음과 같다:
@XmlType
public class Type1{
private List<RelationCanonical> relations;
@XmlElement
public List<RelationCanonical> getRelations(){
return this.relations;
}
public void setRelations(List<RelationCanonical> relations){
this.relations = relations;
}
}
고
@XmlRootElement
public class Type2{
private List<Type1> type1s;
@XmlElement
public List<Type1> getType1s(){
return this.type1s;
}
public void setType1s(List<Type1> type1s){
this.type1s= type1s;
}
}
당신은 또한 확인 를 포함 섹션에서 J5EE 튜토리얼 고 비공식 포함 안내.
다른 팁
그것이 당신의 목적에 맞는 경우 항상 다음과 같은 배열을 정의 할 수 있습니다.
YourType[]
JAXB는 확실히 그것이 무엇인지 알아낼 수 있으며 클라이언트 측면을 즉시 사용할 수 있어야합니다. 또한 목록을 통해 서버에서 검색된 배열을 수정할 수 없지만 웹 서비스가 제공 한 메소드를 통해 수정할 수 없으므로 그렇게하는 것이 좋습니다.
모든 수업을 위해이 작업을하고 싶다면.
return items.size() > 0 ? items.toArray((Object[]) Array.newInstance(
items.get(0).getClass(), 0)) : new Object[0];
내부 "목록"대신 "Arraylist"를 사용할 수 있습니다.