Serializers implements Serializable { static void serialize(DataOutput out, Serializers serializers) throws IOException { StringBuilder msg = new StringBuilder(String.format("Serialize %d serializer classes:", serializers.serializers.values().size())); int size = serializers.serializers.values().size(); out.writeInt(size); if (size > 0) { for (SerializerWrapper sw : serializers.serializers.values()) { int index = sw.index; String name = sw.serializer.getClass().getName(); out.writeInt(index); out.writeUTF(name); msg.append(String.format("%n (%d) %s", index, name)); } LOGGER.info(msg.toString()); } } Serializers(); synchronized void registerSerializer(Serializer serializer); Serializer getSerializer(Class cls); @Override boolean equals(Object o);  }
@Test public void testSerialize() throws Throwable { _serializers.registerSerializer(new ColorSerializer()); DataInputOutput dio = new DataInputOutput(); Serializers.serialize(dio, _serializers); byte[] bytes = dio.toByteArray(); dio = new DataInputOutput(bytes); _serializers.clear(); Serializers.deserialize(dio, _serializers); Assert.assertNotNull(_serializers.getSerializer(Color.class)); Assert.assertEquals(_serializers.getIndex(Color.class), 0); Assert.assertNotNull(_serializers.getSerializer(0)); }