@Test public void testSerializationOfTwoRows() throws IOException { final TypeInformation<Row> rowSchema = Types.ROW_NAMED( new String[] {"f1", "f2", "f3"}, Types.INT, Types.BOOLEAN, Types.STRING); final Row row1 = new Row(3); row1.setField(0, 1); row1.setField(1, true); row1.setField(2, "str"); final JsonRowSerializationSchema serializationSchema = new JsonRowSerializationSchema.Builder(rowSchema) .build(); final JsonRowDeserializationSchema deserializationSchema = new JsonRowDeserializationSchema.Builder(rowSchema) .build(); byte[] bytes = serializationSchema.serialize(row1); assertEquals(row1, deserializationSchema.deserialize(bytes)); final Row row2 = new Row(3); row2.setField(0, 10); row2.setField(1, false); row2.setField(2, "newStr"); bytes = serializationSchema.serialize(row2); assertEquals(row2, deserializationSchema.deserialize(bytes)); }
@Override public byte[] serialize(Row row) { if (node == null) { node = mapper.createObjectNode(); } try { runtimeConverter.convert(mapper, node, row); return mapper.writeValueAsBytes(node); } catch (Throwable t) { throw new RuntimeException("Could not serialize row '" + row + "'. " + "Make sure that the schema matches the input.", t); } }
JsonRowSerializationSchema implements SerializationSchema<Row> { @Override public byte[] serialize(Row row) { if (node == null) { node = mapper.createObjectNode(); } try { runtimeConverter.convert(mapper, node, row); return mapper.writeValueAsBytes(node); } catch (Throwable t) { throw new RuntimeException("Could not serialize row '" + row + "'. " + "Make sure that the schema matches the input.", t); } } }
JsonRowSerializationSchema implements SerializationSchema<Row> { @Override public byte[] serialize(Row row) { if (node == null) { node = mapper.createObjectNode(); } try { runtimeConverter.convert(mapper, node, row); return mapper.writeValueAsBytes(node); } catch (Throwable t) { throw new RuntimeException("Could not serialize row '" + row + "'. " + "Make sure that the schema matches the input.", t); } } @Deprecated  JsonRowSerializationSchema(TypeInformation<Row> typeInfo); }
JsonRowSerializationSchema implements SerializationSchema<Row> { @Override public byte[] serialize(Row row) { if (node == null) { node = mapper.createObjectNode(); } try { runtimeConverter.convert(mapper, node, row); return mapper.writeValueAsBytes(node); } catch (Throwable t) { throw new RuntimeException("Could not serialize row '" + row + "'. " + "Make sure that the schema matches the input.", t); } } @Deprecated  JsonRowSerializationSchema(TypeInformation<Row> typeInfo); @Override byte[] serialize(Row row); @Override boolean equals(Object o); @Override int hashCode(); }
JsonRowSerializationSchema implements SerializationSchema<Row> { @Override public byte[] serialize(Row row) { if (node == null) { node = mapper.createObjectNode(); } try { runtimeConverter.convert(mapper, node, row); return mapper.writeValueAsBytes(node); } catch (Throwable t) { throw new RuntimeException("Could not serialize row '" + row + "'. " + "Make sure that the schema matches the input.", t); } } @Deprecated  JsonRowSerializationSchema(TypeInformation<Row> typeInfo); @Override byte[] serialize(Row row); @Override boolean equals(Object o); @Override int hashCode();  }