@Test public void testSerializer() throws RedisSerializerException { String res = serialize(new HashMap<String, String>() {{ put("message", "message \"abc\" def"); put("host", "this-host"); put("@timestamp", "06/19/2015 10:02:33.12345"); }} ); String[] parts = res.split("(\\{\"|\"\\:\"|\",\"|\"\\})"); int count = 0; int keyCount = 0; int valueCount = 0; for (String part : parts) { ++count; if (part.isEmpty() || part.equals("\n")) { } else if ("message".equals(part)) { ++keyCount; } else if ("host".equals(part)) { ++keyCount; } else if ("@timestamp".equals(part)) { ++keyCount; } else if ("message \\\"abc\\\" def".equals(part)) { ++valueCount; } else if ("this-host".equals(part)) { ++valueCount; } else if ("06/19/2015 10:02:33.12345".equals(part)) { ++valueCount; } else { throw new RuntimeException(String.format("unknown element <%s>", part)); } } assertTrue(count == 7); assertTrue(keyCount == 3); assertTrue(valueCount == 3); }
@Override public byte[] serialize(Event event) throws RedisSerializerException { JsonObject jsonObject = new JsonObject(); for (Map.Entry<String, String> entry : event.getHeaders().entrySet()) { jsonObject.addProperty(entry.getKey(), entry.getValue()); } return jsonObject.toString().getBytes(); }
JsonSerializer implements Serializer { @Override public byte[] serialize(Event event) throws RedisSerializerException { JsonObject jsonObject = new JsonObject(); for (Map.Entry<String, String> entry : event.getHeaders().entrySet()) { jsonObject.addProperty(entry.getKey(), entry.getValue()); } return jsonObject.toString().getBytes(); } }
JsonSerializer implements Serializer { @Override public byte[] serialize(Event event) throws RedisSerializerException { JsonObject jsonObject = new JsonObject(); for (Map.Entry<String, String> entry : event.getHeaders().entrySet()) { jsonObject.addProperty(entry.getKey(), entry.getValue()); } return jsonObject.toString().getBytes(); }  }
JsonSerializer implements Serializer { @Override public byte[] serialize(Event event) throws RedisSerializerException { JsonObject jsonObject = new JsonObject(); for (Map.Entry<String, String> entry : event.getHeaders().entrySet()) { jsonObject.addProperty(entry.getKey(), entry.getValue()); } return jsonObject.toString().getBytes(); }  @Override byte[] serialize(Event event); @Override void configure(Context context); @Override void configure(ComponentConfiguration componentConfiguration); }
JsonSerializer implements Serializer { @Override public byte[] serialize(Event event) throws RedisSerializerException { JsonObject jsonObject = new JsonObject(); for (Map.Entry<String, String> entry : event.getHeaders().entrySet()) { jsonObject.addProperty(entry.getKey(), entry.getValue()); } return jsonObject.toString().getBytes(); }  @Override byte[] serialize(Event event); @Override void configure(Context context); @Override void configure(ComponentConfiguration componentConfiguration);  }