org.wildfly.clustering.marshalling.protostream.DefaultSerializationContext Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.clustering.marshalling.protostream;
import java.io.IOException;
import org.infinispan.protostream.BaseMarshaller;
import org.infinispan.protostream.ImmutableSerializationContext;
import org.infinispan.protostream.ProtobufTagMarshaller;
import org.infinispan.protostream.impl.SerializationContextImpl;
import org.infinispan.protostream.impl.TagWriterImpl;
/**
* Decorates {@link SerializationContextImpl}, ensuring that all registered marshallers implement {@link ProtoStreamMarshaller}.
* We have to use the decorator pattern since SerializationContextImpl is final.
* @author Paul Ferraro
*/
public class DefaultSerializationContext extends NativeSerializationContext implements SerializationContext {
private final org.infinispan.protostream.SerializationContext context;
public DefaultSerializationContext(org.infinispan.protostream.SerializationContext context) {
super(context);
this.context = context;
}
@Override
public ProtoStreamMarshaller getMarshaller(T object) {
return (ProtoStreamMarshaller) this.context.getMarshaller(object);
}
@SuppressWarnings("unchecked")
@Override
public ProtoStreamMarshaller getMarshaller(String fullTypeName) {
return (ProtoStreamMarshaller) this.context.getMarshaller(fullTypeName);
}
@Override
public ProtoStreamMarshaller getMarshaller(Class clazz) {
return (ProtoStreamMarshaller) this.context.getMarshaller(clazz);
}
@Override
public void registerMarshaller(ProtoStreamMarshaller> marshaller) {
this.context.registerMarshaller(marshaller);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void registerMarshaller(BaseMarshaller> marshaller) {
if (marshaller instanceof ProtoStreamMarshaller) {
this.registerMarshaller((ProtoStreamMarshaller>) marshaller);
} else if (marshaller instanceof ProtobufTagMarshaller) {
// Adapt native ProtobufTagMarshaller to ProtoStreamMarshaller interface
ProtobufTagMarshaller