KafkaToJavaSerializer implements Serializer<String, StratioStreamingMessage> { @Override public StratioStreamingMessage serialize(String object) { return gson.fromJson(object, StratioStreamingMessage.class); } KafkaToJavaSerializer(Gson gson); @Override StratioStreamingMessage serialize(String object); @Override String deserialize(StratioStreamingMessage object); @Override List<StratioStreamingMessage> serialize(List<String> object); @Override List<String> deserialize(List<StratioStreamingMessage> object);  }
@Test public void testSeserialize() throws Exception { String doc= "{\"streamName\":\"testStream\",\"timestamp\":1234567890,\"columns\":[{\"column\":\"name\",\"type\":\"STRING\",\"value\":\"name\"},{\"column\":\"timestamp\",\"type\":\"DOUBLE\",\"value\":\"0.0\"},{\"column\":\"value\",\"type\":\"INTEGER\",\"value\":3},{\"column\":\"enabled\",\"type\":\"BOOLEAN\",\"value\":true},{\"column\":\"numberl\",\"type\":\"LONG\",\"value\":123},{\"column\":\"numberf\",\"type\":\"FLOAT\",\"value\":13.0}],\"queries\":[],\"activeActions\":[\"LISTEN\"]}"; StratioStreamingMessage message= serializer.serialize(doc); assertEquals("Expected stream name not found", "testStream", message.getStreamName()); assertEquals("Expected value not found", "name", message.getColumns().get(0).getValue()); }
@Test public void testSerializeList() throws Exception { List<String> docs= new ArrayList<>(); String doc= "{\"streamName\":\"testStream\",\"timestamp\":1234567890,\"columns\":[{\"column\":\"name\",\"type\":\"STRING\",\"value\":\"name\"},{\"column\":\"timestamp\",\"type\":\"DOUBLE\",\"value\":\"0.0\"},{\"column\":\"value\",\"type\":\"INTEGER\",\"value\":3},{\"column\":\"enabled\",\"type\":\"BOOLEAN\",\"value\":true},{\"column\":\"numberl\",\"type\":\"LONG\",\"value\":123},{\"column\":\"numberf\",\"type\":\"FLOAT\",\"value\":13.0}],\"queries\":[],\"activeActions\":[\"LISTEN\"]}"; String doc2= "{\"streamName\":\"testStream\",\"timestamp\":1234567890,\"columns\":[{\"column\":\"name\",\"type\":\"STRING\",\"value\":\"name2\"},{\"column\":\"timestamp\",\"type\":\"DOUBLE\",\"value\":\"0.0\"},{\"column\":\"value\",\"type\":\"INTEGER\",\"value\":3},{\"column\":\"enabled\",\"type\":\"BOOLEAN\",\"value\":true},{\"column\":\"numberl\",\"type\":\"LONG\",\"value\":123},{\"column\":\"numberf\",\"type\":\"FLOAT\",\"value\":13.0}],\"queries\":[],\"activeActions\":[\"LISTEN\"]}"; docs.add(doc); docs.add(doc2); List<StratioStreamingMessage> messages= serializer.serialize(docs); assertEquals(2, messages.size()); assertEquals("Expected stream name not found", "testStream", messages.get(0).getStreamName()); assertEquals("Expected stream name not found", "testStream", messages.get(1).getStreamName()); }