@Test public void shouldSerializeToStringUsingStringSerializerSpecificMethodIfSerializerIsOfSpecificInstance() throws Exception { StringSerializer serializer = mock(StringSerializer.class); when(serializer.serialize("arg", UTF8)).thenReturn("serialized"); String actual = Serializers.serialize(serializer, "arg", UTF8); assertEquals("serialized", actual); }
public static <T> String serialize(Serializer<T> serializer, T value, Charset charset) throws Exception { if(serializer instanceof StringSerializer) { return ((StringSerializer<T>)serializer).serialize(value, charset); }else{ ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.serialize(value, charset, out); return new String(out.toByteArray(), charset); } }
Serializers { public static <T> String serialize(Serializer<T> serializer, T value, Charset charset) throws Exception { if(serializer instanceof StringSerializer) { return ((StringSerializer<T>)serializer).serialize(value, charset); }else{ ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.serialize(value, charset, out); return new String(out.toByteArray(), charset); } } }
Serializers { public static <T> String serialize(Serializer<T> serializer, T value, Charset charset) throws Exception { if(serializer instanceof StringSerializer) { return ((StringSerializer<T>)serializer).serialize(value, charset); }else{ ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.serialize(value, charset, out); return new String(out.toByteArray(), charset); } } private  Serializers(); }
Serializers { public static <T> String serialize(Serializer<T> serializer, T value, Charset charset) throws Exception { if(serializer instanceof StringSerializer) { return ((StringSerializer<T>)serializer).serialize(value, charset); }else{ ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.serialize(value, charset, out); return new String(out.toByteArray(), charset); } } private  Serializers(); static String serialize(Serializer<T> serializer, T value, Charset charset); }
Serializers { public static <T> String serialize(Serializer<T> serializer, T value, Charset charset) throws Exception { if(serializer instanceof StringSerializer) { return ((StringSerializer<T>)serializer).serialize(value, charset); }else{ ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.serialize(value, charset, out); return new String(out.toByteArray(), charset); } } private  Serializers(); static String serialize(Serializer<T> serializer, T value, Charset charset);  }