迁移到java17.So将包迁移到Jakarta.*。
版本:jakbet.xml.bind-api = 4.0.0,com.sun.xml.bind/jaxb-impl = 2.0.1
现在面临的问题是:
jakmart.xml.bind.PropertyException:name:com.sun.xml.bind.namespacePrefixMapper value:com.abc $jakmart.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:355)at org.glassfish.jaxb.runtime.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:492)
如果我将- com.sun.xml.bind/jaxb-impl移动到4.0.2,我不会看到-pacepresefixMapper。
在更改为org.glassfish.jaxb:jaxb-runtime之后,我看到如下错误:“jakslip.xml.bind.PropertyException:name:org.glassfish.jaxb.runtime.marshaller. pacePrefixMapper value:com.fusionone.wsg.provision.resource.BaseMarshaller$pacePrefixMapperImpl@4cd619db at jakslip.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl. java:355)at org.glassfish.jaxb.runtime.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:492)
更多代码:
public static String NAMESPACE_PROPERTY =
"org.glassfish.jaxb.runtime.marshaller.
NamespacePrefixMapper";
public static String A1NAMESPACE = "a1";
public static String NO_NAMESPACE = "";
public static String NAMESPACEURI ="http://www.example.com/xmlns/a1";
public BaseMarshaller(JAXBContext jaxContext) throws JAXBException {
this(jaxContext, Constants.SCHEMA_LOCATION);
}
public BaseMarshaller(JAXBContext jaxContext, String schemaLocation) throws JAXBException {
m = jaxContext.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation);
m.setProperty(Constants.NAMESPACE_PROPERTY, new NamespacePrefixMapperImpl());-> **this is giving exception**
}
new NamespacePrefixMapperImpl() calls , below :
public static class NamespacePrefixMapperImpl extends NamespacePrefixMapper {
@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean arg2) {
if (Constants.NAMESPACEURI.equals(namespaceUri)) {
return Constants.A1NAMESPACE;
}
return Constants.NO_NAMESPACE;
}
}
字符串
2条答案
按热度按时间vngu2lb81#
当迁移到JAXB 4时,您应该使用以下代码而不是
com.sun.xml.bind:jaxb-impl
:字符串
您还应该在API和impl之间对齐主版本号。
命名空间前缀Map器已从
com.sun.xml.bind.marshaller.NamespacePrefixMapper
移动到org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper
。umuewwlo2#
更新属性与关键'org.glassfish.jaxb.namespacePrefixMapper' .问题得到解决!
m.setProperty(“org.glassfish.jaxb.namespacePrefixMapper”,new namespacePrefixMapperImpl());