use of org.pentaho.di.trans.steps.jsoninput.reader.FastJsonReader in project pentaho-kettle by pentaho.
the class JsonInput method createReader.
private void createReader() throws KettleException {
data.reader = new FastJsonReader(meta.getInputFields(), log);
data.reader.setIgnoreMissingPath(meta.isIgnoreMissingPath());
}
use of org.pentaho.di.trans.steps.jsoninput.reader.FastJsonReader in project pentaho-kettle by pentaho.
the class JsonInputTest method testJsonInputPathResolution.
@Test
public void testJsonInputPathResolution() throws KettleException {
JsonInputField inputField = new JsonInputField("value");
final String PATH = "$[*].name";
inputField.setPath(PATH);
inputField.setType(ValueMetaInterface.TYPE_STRING);
JsonInputMeta inputMeta = createSimpleMeta("json", inputField);
VariableSpace variables = new Variables();
JsonInput jsonInput = null;
try {
jsonInput = createJsonInput("json", inputMeta, variables, new Object[] { getSampleJson() });
JsonInputData data = (JsonInputData) Whitebox.getInternalState(jsonInput, "data");
FastJsonReader reader = (FastJsonReader) Whitebox.getInternalState(data, "reader");
RowSet rowset = reader.parse(new ByteArrayInputStream(getSampleJson().getBytes()));
List results = (List) Whitebox.getInternalState(rowset, "results");
JSONArray jsonResult = (JSONArray) results.get(0);
assertEquals(1, jsonResult.size());
assertEquals("United States of America", jsonResult.get(0));
} catch (InvalidPathException pathException) {
assertNull(jsonInput);
}
}
use of org.pentaho.di.trans.steps.jsoninput.reader.FastJsonReader in project pentaho-kettle by pentaho.
the class JsonInput method init.
@Override
protected boolean init() {
data.rownr = 1L;
data.nrInputFields = meta.getInputFields().length;
data.repeatedFields = new BitSet(data.nrInputFields);
for (int i = 0; i < data.nrInputFields; i++) {
JsonInputField field = meta.getInputFields()[i];
if (field.isRepeated()) {
data.repeatedFields.set(i);
}
}
try {
// Init a new JSON reader
data.reader = new FastJsonReader(this, meta.getInputFields(), meta.isDefaultPathLeafToNull(), meta.isIgnoreMissingPath(), meta.isIncludeNulls(), log);
} catch (KettleException e) {
logError(e.getMessage());
return false;
}
return true;
}
Aggregations