我已经遵循了这个example,当输入xml具有变量名称外壳时,我可以忽略这种情况。
但是,当我的Java变量有一个camelCase名称时,我将getter和setter编写为getCamelCase和setCamelCase,但是预期的getter / setter是getCamelcase和setCamelcase。
拥有{g,s} etCamelCase的唯一方法是在getter / setter之上指定@XmlAttribute(name =“camelcase”)。
我认为我班级中方法的反映将方法视为区分大小写。有没有办法避免必须添加@XmlAttribute(name =“camelcase”)
@XmlRootElement(name = "blah")
public class Blah {
String listName;
@XmlAttribute(name = "listname") // without "listname" the attribute is not set.
public String getListName() {
return listName;
}
public void setListName(String listName) {
this.listName = listName;
}
}
驱动程序代码。
String filename = "blah.xml";
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(filename));
Unmarshaller jaxbUnmarshaller = JAXBContext.newInstance(Blah.class).createUnmarshaller();
Blah blah = (Blah) jaxbUnmarshaller.unmarshal(new ToLowerCaseNamesStreamReaderDelegate(xsr));
System.out.println("blah.getListname() = " + blah.getListName());