incubator-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joao Boto <b...@boto.pro>
Subject complex json file
Date Tue, 11 Nov 2014 15:55:32 GMT
i'm trying to understand how to read a complex json file..

i started with this json (but will work with a much more complex):
{
"name":{ "first":"Joe", "last":"Sixpack" },
"gender":"MALE",
"verified":false,
"userImage":"Rm9vYmFyIQ=="
}

trying to do what Kasper told me on
https://issues.apache.org/jira/browse/METAMODEL-38

I wrote the code below, but i can't get "first" and "last" fields..

SimpleTableDef custTable = new SimpleTableDef(
"customer",
new String[] {"name.first","name.last","gender","verified","userimage"}
);

SchemaBuilder schema = new SimpleTableDefSchemaBuilder("tester", custTable)
;
JsonDataContext dc = new JsonDataContext(new FileResource(new
File("src/test/resources/datafeed.json")),schema);
Table table = dc.getDefaultSchema().getTableByName("customer");
Column firstName = table.getColumnByName("name.first");
Column lastName = table.getColumnByName("name.last");
Column gender = table.getColumnByName("gender");
DataSet dataSet =
dc.query().from(table).select(firstName,lastName,gender).execute();
while (dataSet.next()) {
String sFirstName = (String) dataSet.getRow().getValue(firstName);
String sLastName = (String) dataSet.getRow().getValue(lastName);
String sGender = (String) dataSet.getRow().getValue(gender);
}

can someone tell me what I'm doing wrong or indicate which way to go?

thanks

Best regards

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message