@Test public void testDeeplyNestedArraysAndRecords() throws IOException, MalformedRecordException { InputStream is = new FileInputStream("src/test/resources/xml/people_complex1.xml"); XMLRecordReader reader = new XMLRecordReader(is, getSchemaForComplexData(), true, null, "CONTENT", dateFormat, timeFormat, timestampFormat, Mockito.mock(ComponentLog.class)); Record first = reader.nextRecord(true, true); Object[] grandchildren_arr = (Object[]) first.getValue("CHILDREN"); Record first_1_1_1 = (Record)(((Object[])((Record) grandchildren_arr[0]).getValue("CHILD"))[0]); assertEquals("daughter", first_1_1_1.getValue("ROLE")); assertEquals("1-1-1", first_1_1_1.getValue("ID")); assertEquals("Selina", first_1_1_1.getValue("NAME")); Record first_1_1_2 = (Record)(((Object[])((Record) grandchildren_arr[0]).getValue("CHILD"))[1]); assertEquals("son", first_1_1_2.getValue("ROLE")); assertEquals("1-1-2", first_1_1_2.getValue("ID")); assertEquals("Hans", first_1_1_2.getValue("NAME")); Record first_1_1_3 = (Record)(((Object[])((Record) grandchildren_arr[1]).getValue("CHILD"))[0]); assertEquals("daughter", first_1_1_3.getValue("ROLE")); assertEquals("1-2-1", first_1_1_3.getValue("ID")); assertEquals("Selina2", first_1_1_3.getValue("NAME")); Record first_1_1_4 = (Record)(((Object[])((Record) grandchildren_arr[1]).getValue("CHILD"))[1]); assertEquals("son", first_1_1_4.getValue("ROLE")); assertEquals("1-2-2", first_1_1_4.getValue("ID")); assertEquals("Hans2", first_1_1_4.getValue("NAME")); Record second = reader.nextRecord(true, true); Object[] grandchildren_arr2 = (Object[]) second.getValue("CHILDREN"); Record second_2_1_1 = (Record)(((Object[])((Record) grandchildren_arr2[0]).getValue("CHILD"))[0]); assertEquals("daughter", second_2_1_1.getValue("ROLE")); assertEquals("2-1-1", second_2_1_1.getValue("ID")); assertEquals("Selina3", second_2_1_1.getValue("NAME")); }
@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();  }