ByteArrayToHexSerializer extends JsonSerializer<byte[]> { @Override public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers) throws IOException { if (value != null) { gen.writeString("\\x" + Hex.encodeHexString(value)); } }  @Override void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers);  }
@Test void testNullBytes() throws Exception { new ByteArrayToHexSerializer().serialize(null, jsonGenerator, null); verifyNoInteractions(jsonGenerator); }
@Test void testEmptyBytes() throws Exception { new ByteArrayToHexSerializer().serialize(new byte[0], jsonGenerator, null); verify(jsonGenerator).writeString("\\x"); }
@Test void testBytes() throws Exception { new ByteArrayToHexSerializer().serialize(new byte[] {0b0, 0b1, 0b10, 0b01111111}, jsonGenerator, null); verify(jsonGenerator).writeString("\\x0001027f"); }