超出Java 1.8.0_40的解组工作无法按预期进行

时间:2019-06-20 03:21:54

标签: java xml spring jaxb marshalling

我们正在尝试将XML解组到对象。 XML作为SOAP响应出现,如下所示:

<button id="TheButton">
OK
</button>

Class定义如下:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.myorg.com/Services/1.1">
   <s:Body>
      <s:Fault>
         <s:faultcode>s:Client.TokenRefreshRequired</s:faultcode>
         <s:faultstring>TokenRefreshRequired</s:faultstring>
         <s:detail>
            <ns:refreshTokenResult>
               <ns:authToken>refreshed-access-token1</ns:authToken>
               <ns:privateKey>refreshed-refresh-token1</ns:privateKey>
            </ns:refreshTokenResult>
         </s:detail>
      </s:Fault>
   </s:Body>
</s:Envelope>

在Java 1.8.0_40之前可以正常工作,但除此之外,解组似乎不起作用。 LegacyResponse对象中的所有值均为null。任何帮助,将不胜感激。 日志显示以下内容:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Fault", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
public class LegacyResponse {

    @XmlElement(name = "faultcode")
    private String faultCode;

    @XmlElement(name = "faultstring")
    private String faultstring;

    @XmlElement(name = "detail")
    private Detail detail;

    public LegacyResponse() {
    }

    // For testing needs
    public LegacyResponse(String faultCode, String faultstring, String token, String privateKey) {
        this.faultCode = faultCode;
        this.faultstring = faultstring;
        this.detail = new Detail(token, privateKey);
    }

    public Detail getDetail() {
        return detail;
    }

    public String getFaultCode() {
        return faultCode;
    }

    public String getFaultstring() {
        return faultstring;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("LegacyResponse{");
        sb.append("faultCode='").append(faultCode).append('\'');
        sb.append(", faultstring='").append(faultstring).append('\'');
        sb.append(", detail=").append(detail);
        sb.append('}');
        return sb.toString();
    }

    public static class Detail {

        @XmlElement(name = "refreshTokenResult", namespace = "http://www.myorg.com/Services/1.1")
        private RefreshTokenResult refreshTokenResult;

        /**
         * This is a wrapper for the detail object, used only for a special case
         */
        @XmlElement(name = "customFaultDetail", namespace = "http://www.myorg.com/Services/1.1")
        private Detail customDetail;

        public Detail() {
        }

        // For testing needs
        public Detail(String authToken, String privateKey) {
            this.refreshTokenResult = new RefreshTokenResult(authToken, privateKey);
        }

        public RefreshTokenResult getRefreshTokenResult() {
            return refreshTokenResult;
        }

        public Detail getCustomDetail() {
            return customDetail;
        }

        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("Detail{");
            sb.append("refreshTokenResult=").append(refreshTokenResult);
            sb.append('}');
            return sb.toString();
        }
    }
}

0 个答案:

没有答案