Reputation: 34900
Having xml:
<root>
<person id = "123"/>
</root>
Bean mapping:
public class Root {
private Person person;
public void setPerson(Person person) ...
}
public class Person {
String id;
public void setId(String id) ...
}
I have no idea, how can to implement digester3
's pattern for setting id
of Person
class using its setter (setId(String id)
) in such style:
new AbstractRulesModule() {
@Override
protected void configure() {
forPattern("root").createObject().ofType(Root.class);
forPattern("root/person").createObject().ofType(Person.class).then().setNext("setPerson");
}
}
Upvotes: 2
Views: 444
Reputation: 17422
Use callMethod() and callParam(). Your code would be something like this:
new AbstractRulesModule() {
@Override
protected void configure() {
forPattern("root").createObject().ofType(Root.class);
forPattern("root/person").createObject().ofType(Person.class).then()
.callMethod("setId").withParamCount(1).then()
.callParam().ofIndex(0).fromAttribute("id").then()
.setNext("setPerson");
}
}
You can consult the javadoc of digester3 to have a better idea.
Upvotes: 3