使用以下转换可解决XML转JavaBean中属性值为空问题
factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
忽略命名空间即可
public static Object convertXmlStrToObject(Class clazz, String xmlStr) {
JAXBElement xmlObject = null;
try {
JAXBContext context = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = context.createUnmarshaller();
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
XMLEventReader someSource = factory.createXMLEventReader(new ByteArrayInputStream((xmlStr.getBytes(StandardCharsets.UTF_8))));
xmlObject = unmarshaller.unmarshal(someSource, clazz);
} catch (JAXBException | XMLStreamException e) {
e.printStackTrace();
}
return xmlObject.getValue();
}