@Test public void testMissingAndExtraFieldInWriteRecord() throws IOException { final List<RecordField> fields = new ArrayList<>(); fields.add(new RecordField("id", RecordFieldType.STRING.getDataType())); fields.add(new RecordField("name", RecordFieldType.STRING.getDataType())); final RecordSchema schema = new SimpleRecordSchema(fields); final Map<String, Object> values = new LinkedHashMap<>(); values.put("id", "1"); values.put("dob", "1/1/1970"); final Record record = new MapRecord(schema, values); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final WriteJsonResult writer = new WriteJsonResult(Mockito.mock(ComponentLog.class), schema, new SchemaNameAsAttribute(), baos, false, NullSuppression.NEVER_SUPPRESS, OutputGrouping.OUTPUT_ARRAY, null, null, null)) { writer.beginRecordSet(); writer.writeRecord(record); writer.finishRecordSet(); } final byte[] data = baos.toByteArray(); final String expected = "[{\"id\":\"1\",\"name\":null}]"; final String output = new String(data, StandardCharsets.UTF_8); assertEquals(expected, output); }
@Override public Map<String, String> writeRecord(final Record record) throws IOException { if (!isActiveRecordSet()) { generator.flush(); schemaAccess.writeHeader(recordSchema, getOutputStream()); } writeRecord(record, recordSchema, generator, g -> g.writeStartObject(), g -> g.writeEndObject(), true); return schemaAccess.getAttributes(recordSchema); }
WriteJsonResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public Map<String, String> writeRecord(final Record record) throws IOException { if (!isActiveRecordSet()) { generator.flush(); schemaAccess.writeHeader(recordSchema, getOutputStream()); } writeRecord(record, recordSchema, generator, g -> g.writeStartObject(), g -> g.writeEndObject(), true); return schemaAccess.getAttributes(recordSchema); } }
WriteJsonResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public Map<String, String> writeRecord(final Record record) throws IOException { if (!isActiveRecordSet()) { generator.flush(); schemaAccess.writeHeader(recordSchema, getOutputStream()); } writeRecord(record, recordSchema, generator, g -> g.writeStartObject(), g -> g.writeEndObject(), true); return schemaAccess.getAttributes(recordSchema); } WriteJsonResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint,
        final NullSuppression nullSuppression, final OutputGrouping outputGrouping, final String dateFormat, final String timeFormat, final String timestampFormat); }
WriteJsonResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public Map<String, String> writeRecord(final Record record) throws IOException { if (!isActiveRecordSet()) { generator.flush(); schemaAccess.writeHeader(recordSchema, getOutputStream()); } writeRecord(record, recordSchema, generator, g -> g.writeStartObject(), g -> g.writeEndObject(), true); return schemaAccess.getAttributes(recordSchema); } WriteJsonResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint,
        final NullSuppression nullSuppression, final OutputGrouping outputGrouping, final String dateFormat, final String timeFormat, final String timestampFormat); @Override void close(); @Override void flush(); @Override Map<String, String> writeRecord(final Record record); @Override WriteResult writeRawRecord(final Record record); @Override String getMimeType(); }
WriteJsonResult extends AbstractRecordSetWriter implements RecordSetWriter, RawRecordWriter { @Override public Map<String, String> writeRecord(final Record record) throws IOException { if (!isActiveRecordSet()) { generator.flush(); schemaAccess.writeHeader(recordSchema, getOutputStream()); } writeRecord(record, recordSchema, generator, g -> g.writeStartObject(), g -> g.writeEndObject(), true); return schemaAccess.getAttributes(recordSchema); } WriteJsonResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint,
        final NullSuppression nullSuppression, final OutputGrouping outputGrouping, final String dateFormat, final String timeFormat, final String timestampFormat); @Override void close(); @Override void flush(); @Override Map<String, String> writeRecord(final Record record); @Override WriteResult writeRawRecord(final Record record); @Override String getMimeType();  }