use of org.apache.flink.streaming.util.serialization.JSONKeyValueDeserializationSchema in project flink by apache.
the class JSONKeyValueDeserializationSchemaTest method testDeserializeWithMetadata.
@Test
public void testDeserializeWithMetadata() throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode initialKey = mapper.createObjectNode();
initialKey.put("index", 4);
byte[] serializedKey = mapper.writeValueAsBytes(initialKey);
ObjectNode initialValue = mapper.createObjectNode();
initialValue.put("word", "world");
byte[] serializedValue = mapper.writeValueAsBytes(initialValue);
JSONKeyValueDeserializationSchema schema = new JSONKeyValueDeserializationSchema(true);
ObjectNode deserializedValue = schema.deserialize(serializedKey, serializedValue, "topic#1", 3, 4);
Assert.assertEquals(4, deserializedValue.get("key").get("index").asInt());
Assert.assertEquals("world", deserializedValue.get("value").get("word").asText());
Assert.assertEquals("topic#1", deserializedValue.get("metadata").get("topic").asText());
Assert.assertEquals(4, deserializedValue.get("metadata").get("offset").asInt());
Assert.assertEquals(3, deserializedValue.get("metadata").get("partition").asInt());
}
use of org.apache.flink.streaming.util.serialization.JSONKeyValueDeserializationSchema in project flink by apache.
the class JSONKeyValueDeserializationSchemaTest method testDeserializeWithoutMetadata.
@Test
public void testDeserializeWithoutMetadata() throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode initialKey = mapper.createObjectNode();
initialKey.put("index", 4);
byte[] serializedKey = mapper.writeValueAsBytes(initialKey);
ObjectNode initialValue = mapper.createObjectNode();
initialValue.put("word", "world");
byte[] serializedValue = mapper.writeValueAsBytes(initialValue);
JSONKeyValueDeserializationSchema schema = new JSONKeyValueDeserializationSchema(false);
ObjectNode deserializedValue = schema.deserialize(serializedKey, serializedValue, "", 0, 0);
Assert.assertTrue(deserializedValue.get("metadata") == null);
Assert.assertEquals(4, deserializedValue.get("key").get("index").asInt());
Assert.assertEquals("world", deserializedValue.get("value").get("word").asText());
}
Aggregations