DelegatingSerializationService extends AbstractSerializationService { @Override public SerializerAdapter serializerFor(Object object) { Class<?> clazz = object == null ? null : object.getClass(); SerializerAdapter serializer = null; if (clazz != null) { serializer = serializersByClass.get(clazz); } if (serializer == null) { try { serializer = delegate.serializerFor(object); } catch (HazelcastSerializationException hse) { throw serializationException(clazz, hse); } } if (serializer == null) { throw active ? serializationException(clazz) : new HazelcastInstanceNotActiveException(); } return serializer; } DelegatingSerializationService(
            Map<Class<?>, ? extends Serializer> serializers,
            AbstractSerializationService delegate
    ); @Override B toData(Object object, DataType type); @Override B toData(Object object, DataType type, PartitioningStrategy strategy); @Override B convertData(Data data, DataType dataType); @Override PortableReader createPortableReader(Data data); @Override PortableContext getPortableContext(); @Override SerializerAdapter serializerFor(Object object); @Override SerializerAdapter serializerFor(int typeId); @Override void dispose(); static InternalSerializationService from(
            SerializationService serializationService,
            Map<String, String> serializerConfigs
    );  }
@Test public void when_triesToFindSerializerForUnregisteredType_then_Fails() { DelegatingSerializationService service = new DelegatingSerializationService(emptyMap(), DELEGATE); assertThatThrownBy(() -> service.serializerFor(new UnregisteredValue())) .isInstanceOf(JetException.class); assertThatThrownBy(() -> service.serializerFor(Integer.MAX_VALUE)) .isInstanceOf(JetException.class); }
@Test public void when_doesNotFind_then_Delegates() { DelegatingSerializationService service = new DelegatingSerializationService(emptyMap(), DELEGATE); assertThat(service.serializerFor(TYPE_ID).getImpl()).isInstanceOf(ValueSerializer.class); assertThat(service.serializerFor(new Value()).getImpl()).isInstanceOf(ValueSerializer.class); }
@Test public void when_multipleTypeSerializersRegistered_then_localHasPrecedence() { Serializer serializer = new ValueSerializer(); Map<Class<?>, Serializer> serializers = ImmutableMap.of(Byte.class, serializer); DelegatingSerializationService service = new DelegatingSerializationService(serializers, DELEGATE); assertThat(service.serializerFor(TYPE_ID).getImpl()).isEqualTo(serializer); assertThat(service.serializerFor(Byte.valueOf((byte) 1)).getImpl()).isEqualTo(serializer); }
@Test public void when_triesToFindSerializerForNullObject_then_Succeeds() { DelegatingSerializationService service = new DelegatingSerializationService(emptyMap(), DELEGATE); assertThat(service.serializerFor(null).getImpl()).isNotNull(); }