use of com.codename1.rad.io.ResultParser in project CodeRAD by shannah.
the class ResultParserTest method dateFormatXMLAttsTest.
private void dateFormatXMLAttsTest() throws Exception {
EntityType personType = new EntityTypeBuilder().string(Person.name).string(Person.email).Date(Person.birthDate).build();
ResultParser parser = new ResultParser(personType).property("/person[0]/@name", Person.name).property("/person[0]/@email", Person.email).property("/person[0]/@dob", Person.birthDate, new SimpleDateFormat("MMM d, yyyy"));
String json = "<person name=\"Paul\" email=\"paul@example.com\" dob=\"December 27, 1978\"></person>";
XMLParser xparser = new XMLParser();
Element root = xparser.parse(new StringReader("<?xml version='1.0'?>\n" + json));
Entity person = parser.parseRow(Result.fromContent(root), personType.newInstance());
assertEqual("Paul", person.getEntity().getText(Person.name));
assertEqual("paul@example.com", person.getEntity().getText(Person.email));
}
Aggregations