@Test public void testDeeplyNestedArraysAndRecordsCoerceFalseDropFalse() throws IOException, MalformedRecordException { InputStream is = new FileInputStream("src/test/resources/xml/people_complex2.xml"); XMLRecordReader reader = new XMLRecordReader(is, new SimpleRecordSchema(Collections.emptyList()), true, null, "CONTENT", dateFormat, timeFormat, timestampFormat, Mockito.mock(ComponentLog.class)); Record first = reader.nextRecord(false, false); assertEquals("1", first.getValue("ID")); assertEquals("Lisa", first.getValue("NAME")); assertEquals("grandmother", first.getValue("ROLE")); Object[] gm_arr = (Object[]) first.getValue("CHILDREN"); assertEquals(2, gm_arr.length); Record gm_hus1_arr_rec = (Record) gm_arr[0]; assertEquals("husband1", gm_hus1_arr_rec.getValue("SPOUSE")); Object[] gm_hus1_arr_rec_arr = (Object[]) gm_hus1_arr_rec.getValue("CHILD"); assertEquals(2, gm_hus1_arr_rec_arr.length); Record child1_1 = (Record) gm_hus1_arr_rec_arr[0]; assertEquals("1-1", child1_1.getValue("ID")); assertEquals("Anna", child1_1.getValue("NAME")); assertEquals("mother", child1_1.getValue("ROLE")); Record child1_1_rec = (Record) child1_1.getValue("CHILDREN"); assertEquals("first husband", child1_1_rec.getValue("ID")); Object[] child1_1_rec_arr = (Object[]) child1_1_rec.getValue("CHILD"); assertEquals(2, child1_1_rec_arr.length); Record child1_1_1 = (Record) child1_1_rec_arr[0]; assertEquals("1-1-1", child1_1_1.getValue("ID")); assertEquals("Selina", child1_1_1.getValue("NAME")); assertEquals("daughter", child1_1_1.getValue("ROLE")); Record child1_1_2 = (Record) child1_1_rec_arr[1]; assertEquals("1-1-2", child1_1_2.getValue("ID")); assertEquals("Hans", child1_1_2.getValue("NAME")); assertEquals("son", child1_1_2.getValue("ROLE")); Record child1_2 = (Record) gm_hus1_arr_rec_arr[1]; assertEquals("1-2", child1_2.getValue("ID")); assertEquals("Catrina", child1_2.getValue("NAME")); assertEquals("mother", child1_2.getValue("ROLE")); Record gm_hus2_arr_rec = (Record) gm_arr[1]; assertEquals("husband2", gm_hus2_arr_rec.getValue("SPOUSE")); Record child1_3 = (Record) gm_hus2_arr_rec.getValue("CHILD"); assertEquals("1-3", child1_3.getValue("ID")); assertEquals("Anna2", child1_3.getValue("NAME")); assertEquals("mother", child1_3.getValue("ROLE")); assertEquals(2, ((Object[])((Record) child1_3.getValue("CHILDREN")).getValue("CHILD")).length); Record second = reader.nextRecord(false, false); assertEquals("2-1-1", ((Record)((Record)((Record)((Record) second.getValue("CHILDREN")) .getValue("CHILD")) .getValue("CHILDREN")) .getValue("CHILD")) .getValue("ID")); }
@Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); @Override Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields); @Override RecordSchema getSchema(); @Override void close(); }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); @Override Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields); @Override RecordSchema getSchema(); @Override void close();  }