正在获取-无法将XML字符串转换为Java对象1个IllegalAnnotationExceptions计数

问题描述 投票:0回答:1

我正在尝试将xml转换为Java对象,但收到错误消息“无法将XML字符串转换为Java对象的1个IllegalAnnotationExceptions计数”。这是我的xml和pojo。

<TelephoneNumberList index="134">
    <TelephoneNumber index="135">
        <TelephoneNumberId index="136">2144844199</TelephoneNumberId>
        <Native index="137">Y</Native>
        <PortedType index="138">NONE</PortedType>
        <Transfer index="139"/>
    </TelephoneNumber>
</TelephoneNumberList>

@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class TelephoneNumberList {
       @XmlAttribute    
       protected String index;   
       @XmlValue
       @XmlElement(name="TelephoneNumber")
       protected List<TelephoneNumber> telephoneNumber;
}

@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class TelephoneNumber {
       @XmlAttribute    
       protected String index;   
       @XmlValue
       @XmlElement(name="TelephoneNumberId")
       protected TelephoneNumberId telephoneNumberId;
       @XmlValue
       @XmlElement(name="Native")
       protected Native nativeValue;
       @XmlValue
       @XmlElement(name="PortedType")
       protected PortedType portedType;
       @XmlValue
       @XmlElement(name="Transfer")
       protected Transfer transfer;
}

@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class TelephoneNumberId {
       @XmlAttribute    
       protected String index;   
       @XmlValue
       @XmlElement(name="")
       protected String value;
}


@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Native {
       @XmlAttribute    
       protected String index;   
       @XmlValue
       @XmlElement(name="")
       protected String value;
}

@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class PortedType {
       @XmlAttribute    
       protected String index;   
       @XmlValue
       @XmlElement(name="")
       protected String value;
}

@Getter
@Setter
@ToString
@NoArgsConstructor
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Transfer {
     @XmlAttribute  
     protected String index;  

}

我收到错误消息“无法将XML字符串转换为IllegalAnnotationExceptions的Java对象1个计数”。

谢谢Bandita Pradhan

xml pojo
1个回答
0
投票

我删除了@XmlValue注释,它起作用了。

© www.soinside.com 2019 - 2024. All rights reserved.