java xmlattribute_获取@ XmlAttribute / @ XmlValue需要引用映射到XML中的文本的Java类型

在下面的代码中,我得到了以下异常。 XmlAttribute / XmlValue无法正常工作,我无法识别: -

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions

@XmlAttribute/@XmlValue need to reference a Java type that maps to text in XML.

this problem is related to the following location:

at public java.util.Set nl.magnus.test.AddressComponent.getLocationTypeSet()

at nl.magnus.test.AddressComponent

我的bean LocationType: -

@XmlRootElement(name = "type")

public class LocationType {

private Integer locationTypeId;

private String type;

private String status;

@Override

public String toString() {

return "LocationType [locationTypeId=" + locationTypeId + ", type=" + type + ", status=" + status + "]";

}

public Integer getLocationTypeId() {

return locationTypeId;

}

public void setLocationTypeId(Integer locationTypeId) {

this.locationTypeId = locationTypeId;

}

public String getType() {

return type;

}

@XmlAttribute(name = "type")

public void setType(String type) {

this.type = type;

}

public String getStatus() {

return status;

}

public void setStatus(String status) {

this.status = status;

}

}

我的bean AddressComponent: -

@XmlRootElement(name = "address_component")

public class AddressComponent {

private String longName;

private String shortName;

private Set locationTypeSet;

public String getLongName() {

return longName;

}

@XmlElement(name = "long_name")

public void setLongName(String longName) {

this.longName = longName;

}

public String getShortName() {

return shortName;

}

@XmlElement(name = "short_name")

public void setShortName(String shortName) {

this.shortName = shortName;

}

public Set getLocationTypeSet() {

return locationTypeSet;

}

@XmlAttribute(name = "type")

public void setLocationTypeSet(Set locationTypeSet) {

this.locationTypeSet = locationTypeSet;

}

@Override

public String toString() {

return "AddressComponent [longName=" + longName + ", shortName=" + shortName + ", locationTypeSet="

+ locationTypeSet + "]";

}

}

My Test class TestSmall: -

public class TestSmall {

public static void main(String[] args) {

try {

File file = new File("test.xml");

JAXBContext jaxbContext = JAXBContext.newInstance(AddressComponent.class);

Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

AddressComponent geoResponse = (AddressComponent) jaxbUnmarshaller.unmarshal(file);

System.out.println(geoResponse);

// Location latLong = geoResponse.getaResult().getGeometry().getLocation();

// System.out.println(latLong.getLatitude()+ ", "+latLong.getLongitude());

} catch (JAXBException e) {

e.printStackTrace();

}

}

}

我的xml test.xml: -

BMC Colony

BMC Colony

neighborhood

political

请建议我所需的配置。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值