use of org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema in project flink by apache.
the class JsonRowSerializationSchemaTest method serializeAndDeserialize.
private Row serializeAndDeserialize(String[] fieldNames, Class[] fieldTypes, Row row) throws IOException {
JsonRowSerializationSchema serializationSchema = new JsonRowSerializationSchema(fieldNames);
JsonRowDeserializationSchema deserializationSchema = new JsonRowDeserializationSchema(fieldNames, fieldTypes);
byte[] bytes = serializationSchema.serialize(row);
return deserializationSchema.deserialize(bytes);
}
use of org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema in project flink by apache.
the class JsonRowSerializationSchemaTest method testSerializeRowWithInvalidNumberOfFields.
@Test(expected = IllegalStateException.class)
public void testSerializeRowWithInvalidNumberOfFields() {
String[] fieldNames = new String[] { "f1", "f2", "f3" };
Row row = new Row(1);
row.setField(0, 1);
JsonRowSerializationSchema serializationSchema = new JsonRowSerializationSchema(fieldNames);
serializationSchema.serialize(row);
}
use of org.apache.flink.streaming.util.serialization.JsonRowSerializationSchema in project flink by apache.
the class JsonRowSerializationSchemaTest method testSerializationOfTwoRows.
@Test
public void testSerializationOfTwoRows() throws IOException {
String[] fieldNames = new String[] { "f1", "f2", "f3" };
Class[] fieldTypes = new Class[] { Integer.class, Boolean.class, String.class };
Row row1 = new Row(3);
row1.setField(0, 1);
row1.setField(1, true);
row1.setField(2, "str");
JsonRowSerializationSchema serializationSchema = new JsonRowSerializationSchema(fieldNames);
JsonRowDeserializationSchema deserializationSchema = new JsonRowDeserializationSchema(fieldNames, fieldTypes);
byte[] bytes = serializationSchema.serialize(row1);
assertEqualRows(row1, deserializationSchema.deserialize(bytes));
Row row2 = new Row(3);
row2.setField(0, 10);
row2.setField(1, false);
row2.setField(2, "newStr");
bytes = serializationSchema.serialize(row2);
assertEqualRows(row2, deserializationSchema.deserialize(bytes));
}
Aggregations