Search in sources :

Example 11 with ResultParser

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));
}
Also used : Entity(com.codename1.rad.models.Entity) Element(com.codename1.xml.Element) StringReader(java.io.StringReader) ResultParser(com.codename1.rad.io.ResultParser) XMLParser(com.codename1.xml.XMLParser) SimpleDateFormat(com.codename1.l10n.SimpleDateFormat)

Aggregations

ResultParser (com.codename1.rad.io.ResultParser)10 Entity (com.codename1.rad.models.Entity)9 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)8 Element (com.codename1.xml.Element)7 XMLParser (com.codename1.xml.XMLParser)6 StringReader (java.io.StringReader)6 ParseException (com.codename1.l10n.ParseException)4 List (java.util.List)4 Map (java.util.Map)4 Log (com.codename1.io.Log)3 ParsingService (com.codename1.rad.io.ParsingService)3 PropertyParserCallback (com.codename1.rad.io.ResultParser.PropertyParserCallback)3 ResultParser.resultParser (com.codename1.rad.io.ResultParser.resultParser)3 com.codename1.rad.models (com.codename1.rad.models)3 BaseEntity.entityTypeBuilder (com.codename1.rad.models.BaseEntity.entityTypeBuilder)3 Result (com.codename1.rad.processing.Result)3 Person (com.codename1.rad.schemas.Person)3 Product (com.codename1.rad.schemas.Product)3 Thing (com.codename1.rad.schemas.Thing)3 AbstractTest (com.codename1.testing.AbstractTest)3