I have a problem using Digester and I hope you can help me. I have the following Bean:
public class MyEntry {
private String entityID;
public String getEntityID() { return this.entityID; }
public void setEntityID(final String entityID) { this.entityID = entityID; }
}
And the following XML structure:
<entries>
<entry>
<MyID>
24309LAGH1
</MyID>
</entry>
</entries>
I use the addSetNestedProperties(…) 开发者_运维百科method of the digester API:
digester.addSetNestedProperties("entries/entry", "MyID", "entryID");
The following exception occurs:
java.lang.NoSuchMethodException: Bean has no property named MyID
Why is digester searching for a property named “MyID”? I specified “entryID” as bean property accorsing to the digester API
Thanks :)
Best regards QStorm
Make sure the name of getters and setters like are uppercase or lowercase of your property "entityID. Probably your getter name is like this --> "getEntityID" try to change for this --> "getentityID"
Edit
Sorry, the property you have to check is --> "MyID"
[original]
You do not use the correct rule to perform your task.
Try using this instead:
digester.addBeanPropertySetter("entries/entry/MyID", "entityID");
Tips: activate the log4j in your main by using for instance BasicConfigurator.configure();
. The output can be very useful.
[edit]
If you want to use addSetNestedProperties
:
public class MyEntry {
private String entityID;
public String getEntityID() { return this.entityID; }
public void setEntityID(final String entityID) { this.entityID = entityID; }
}
and for new Digester().parse(myFile)
;
digester.addObjectCreate("entries/entry", MyEntry.class);
digester.addSetNestedProperties("entries/entry", "MyID", "entityID");
//your propertyName was not the same as in your Bean Class Fields.
and I presume that your Exception was:
java.lang.NoSuchMethodException: Bean has no property named entryID
精彩评论