JAXB “(variable) is not a valid property” on a Res

2019-07-31 18:57发布

I have a webservice:

@WebService()
public interface WMCService {

    @WebMethod(operationName="getGroupInfoFromUserId")
    @ResponseWrapper(className="wmc.web.service.BasicGroupWrapper")
    @WebResult(name="basicGroup")
    BasicGroup getGroupInfoFromUserId(@WebParam(name = "id") Long id);
}

@WebService(endpointInterface="wmc.web.service.WMCService", serviceName="WMCService")
public class WMCServiceImpl implements WMCService {

    @Override
    public BasicGroup getGroupInfoFromUserId(Long id) {
        UserHelper uh = new UserHelper();
        WMCUser user = uh.getById(id);
        if (user != null) {
            return user.getBasicGroup();
        } else {
            return null;
        }
    }
}

and I have the ResponseWrapper:

@XmlRootElement()
@XmlType(name="Group")
@XmlAccessorType(XmlAccessType.FIELD)
public class BasicGroupWrapper {

    @XmlElement(name="groupName")
    private String groupName;
    @XmlElement(name="groupId")
    private Long groupId;
    @XmlTransient
    private BasicGroup basicGroup;

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public Long getGroupId() {
        return groupId;
    }

    public void setGroupId(Long groupId) {
        this.groupId = groupId;
    }

    public void setBasicGroup(BasicGroup group) {
        this.groupName = group.getGroupName();
        this.groupId = group.getId();
        this.basicGroup = group;
    }

    public BasicGroup getBasicGroup() {
        return basicGroup;
    }

}

When I test this operation I get the following error which I can't google a solution to. Maybe you can help.

Caused by: javax.xml.bind.JAXBException: basicGroup is not a valid property on class wmc.web.service.BasicGroupWrapper
            at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(JAXBContextImpl.java:971)
            at com.sun.xml.ws.server.sei.EndpointResponseMessageBuilder$DocLit.<init>(EndpointResponseMessageBuilder.java:203)
        ... 34 more

2条回答
相关推荐>>
2楼-- · 2019-07-31 19:52

I had the same problem when there were MS Web Service and Java client on JBoss. I generated stub classes using wsconsume. And after that I usually deleted package-info.java because I thought that this is redundant class. After that this case reproduced. After some time I tried to include this file (package-info.java) into project. And it solved the problem.

But when I've used Java Web Service (on JBoss) it works perfectly even without package-info class. It's very strange. Just FYI.

Following link was helpful: link

查看更多
做自己的国王
3楼-- · 2019-07-31 19:57

@WebResult(name="basicGroup") this is not part of your WSDL since it's marked as XmlTransient:

@XmlTransient
private BasicGroup basicGroup;

So it won't be able to pick out that part of for your response.

查看更多
登录 后发表回答