use of org.onebusaway.csv_entities.schema.EntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactory method setObjectPropertiesFromJsonUsingCsvFields.
private void setObjectPropertiesFromJsonUsingCsvFields(Object object, JSONObject json, String line) throws JSONException, TransformSpecificationMissingArgumentException {
EntitySchemaFactory entitySchemaFactory = _transformer.getReader().getEntitySchemaFactory();
EntitySchema schema = entitySchemaFactory.getSchema(object.getClass());
BeanWrapper wrapped = BeanWrapperFactory.wrap(object);
Map<String, Object> values = new HashMap<String, Object>();
for (Iterator<?> it = json.keys(); it.hasNext(); ) {
String key = (String) it.next();
Object v = json.get(key);
if (v instanceof JSONArray) {
JSONArray array = (JSONArray) v;
List<Object> asList = new ArrayList<Object>();
for (int i = 0; i < array.length(); ++i) {
asList.add(array.get(i));
}
v = asList;
}
values.put(key, v);
}
CsvEntityContext context = new CsvEntityContextImpl();
for (FieldMapping mapping : schema.getFields()) {
try {
mapping.translateFromCSVToObject(context, values, wrapped);
} catch (MissingRequiredFieldException ex) {
String verboseMessage = "line=" + line + ", context=" + context + ", json=" + json + ", object=" + object;
_log.error("missing required field; details:" + verboseMessage);
throw new TransformSpecificationMissingArgumentException(verboseMessage, ex.getFieldName());
}
}
}
use of org.onebusaway.csv_entities.schema.EntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.
the class EntitySchemaCache method addEntitySchemasFromGtfsReader.
public void addEntitySchemasFromGtfsReader(GtfsReader reader) {
EntitySchemaFactory factory = reader.getEntitySchemaFactory();
for (Class<?> entityType : reader.getEntityClasses()) {
EntitySchema schema = factory.getSchema(entityType);
addEntitySchema(schema);
}
}
Aggregations