java 设置xmlns xsi,如何从JAXB编组的XML文件中删除xmlns:xsi和xsi:type

当使用JAXB生成的类并设置setter方法接受`Object`参数时,XML序列化可能会出现`xmlns:xsi`和`xsi:type`。问题在于方法参数为`Object`,但实际传递的是字符串。解决方法包括将字段类型改为String,使用`jaxb:javaType`绑定,或使用`@XmlElementRef`和`@XmlMixed`组合。
摘要由CSDN通过智能技术生成

I've got a set of JAXB generated classes and some of the classes have setter methods which accepts

"Object" as the parameter. For example:

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name="Car", propOrder = {

"defaultCar"

}

public class Car {

@XmlElement(name = "DefaultCar")

protected Object defaultcar;

public void setDefaultCar(Object value) {

this.defaultCar = value;

}

After I've created instances of these classes in my code, I call the setter methods passing in the required value. Although the method's parameter is Object, the values are most likely to be strings (I've got no control over how it is defined). However, to keep things consistent, I cast the string to Object so that it matches the me

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值