本文整理了Java中com.esotericsoftware.kryo.Kryo.setDefaultSerializer()
方法的一些代码示例,展示了Kryo.setDefaultSerializer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.setDefaultSerializer()
方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:setDefaultSerializer
[英]Sets the serializer factory to use when no #addDefaultSerializer(Class,Class) match an object's type. Default is ReflectionSerializerFactory with FieldSerializer.
[中]设置当没有#addDefaultSerializer(类,类)与对象类型匹配时要使用的序列化程序工厂。默认值为带有FieldSerializer的ReflectionSerializerFactory。
代码示例来源:origin: atomix/atomix
/**
* Creates a Kryo instance.
*
* @return Kryo instance
*/
@Override
public Kryo create() {
LOGGER.trace("Creating Kryo instance for {}", this);
Kryo kryo = new Kryo();
kryo.setClassLoader(classLoader);
kryo.setRegistrationRequired(registrationRequired);
// If compatible serialization is enabled, override the default serializer.
if (compatible) {
kryo.setDefaultSerializer(CompatibleFieldSerializer::new);
}
// TODO rethink whether we want to use StdInstantiatorStrategy
kryo.setInstantiatorStrategy(
new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
for (RegistrationBlock block : registeredBlocks) {
int id = block.begin();
if (id == FLOATING_ID) {
id = kryo.getNextRegistrationId();
}
for (Pair<Class<?>[], Serializer<?>> entry : block.types()) {
register(kryo, entry.getLeft(), entry.getRight(), id++);
}
}
return kryo;
}
代码示例来源:origin: magro/memcached-session-manager
kryo.setDefaultSerializer(new KryoDefaultSerializerFactory.SerializerFactoryAdapter(_defaultSerializerFactory));
代码示例来源:origin: jerrinot/subzero
@Override
public void registerAllSerializers(Kryo kryo) {
for (Map.Entry<Class, Serializer> entry : customerSerializers.entrySet()) {
Class clazz = entry.getKey();
Serializer serializer = entry.getValue();
kryo.register(clazz, serializer);
}
registerSpecialSerializers(kryo);
if (defaultSerializerClass != null) {
kryo.setDefaultSerializer(defaultSerializerClass);
}
}
代码示例来源:origin: mindwind/craft-atom
private static Kryo newKryo() {
Kryo kryo = new Kryo();
kryo.register(RpcBody.class);
kryo.register(RpcMethod.class);
kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
return kryo;
}
代码示例来源:origin: io.craftcode/craft-atom-protocol-rpc
private static Kryo newKryo() {
Kryo kryo = new Kryo();
kryo.register(RpcBody.class);
kryo.register(RpcMethod.class);
kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
return kryo;
}
代码示例来源:origin: techery/snapper
public KryoConverter(Class<T> clazz) {
this.clazz = clazz;
this.kryo = new Kryo();
this.kryo.register(clazz);
this.kryo.register(Date.class, new DateSerializer());
this.kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
this.kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
//
this.input = new Input();
this.output = new Output(new ByteArrayOutputStream());
}
代码示例来源:origin: ks-no/eventstore2
public Kryo getKryo() {
if (tlkryo.get() == null) {
Kryo kryo = new Kryo();
kryo.setInstantiatorStrategy(new SerializingInstantiatorStrategy());
kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
kryo.register(DateTime.class, new JodaDateTimeSerializer());
kryo.setRegistrationRequired(true);
registration.registerClasses(kryo);
tlkryo.set(kryo);
}
return tlkryo.get();
}
代码示例来源:origin: org.onosproject/onlab-misc
/**
* Creates a Kryo instance.
*
* @return Kryo instance
*/
@Override
public Kryo create() {
log.trace("Creating Kryo instance for {}", this);
Kryo kryo = new Kryo();
kryo.setRegistrationRequired(registrationRequired);
// If compatible serialization is enabled, override the default serializer.
if (compatible) {
kryo.setDefaultSerializer(CompatibleFieldSerializer::new);
}
// TODO rethink whether we want to use StdInstantiatorStrategy
kryo.setInstantiatorStrategy(
new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
for (RegistrationBlock block : registeredBlocks) {
int id = block.begin();
if (id == FLOATING_ID) {
id = kryo.getNextRegistrationId();
}
for (Pair<Class<?>[], Serializer<?>> entry : block.types()) {
register(kryo, entry.getLeft(), entry.getRight(), id++);
}
}
return kryo;
}
代码示例来源:origin: io.atomix/atomix-utils
/**
* Creates a Kryo instance.
*
* @return Kryo instance
*/
@Override
public Kryo create() {
log.trace("Creating Kryo instance for {}", this);
Kryo kryo = new Kryo();
kryo.setClassLoader(classLoader);
kryo.setRegistrationRequired(registrationRequired);
// If compatible serialization is enabled, override the default serializer.
if (compatible) {
kryo.setDefaultSerializer(CompatibleFieldSerializer::new);
}
// TODO rethink whether we want to use StdInstantiatorStrategy
kryo.setInstantiatorStrategy(
new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
for (RegistrationBlock block : registeredBlocks) {
int id = block.begin();
if (id == FLOATING_ID) {
id = kryo.getNextRegistrationId();
}
for (Pair<Class<?>[], Serializer<?>> entry : block.types()) {
register(kryo, entry.getLeft(), entry.getRight(), id++);
}
}
return kryo;
}
代码示例来源:origin: com.vmware.dcp/dcp-common
public static Kryo create(boolean isObjectSerializer) {
Kryo k = new Kryo();
k.setDefaultSerializer(VersionFieldSerializer.class);
// Custom serializers for Java 8 date/time
k.addDefaultSerializer(ZonedDateTime.class, ZonedDateTimeSerializer.INSTANCE);
k.addDefaultSerializer(Instant.class, InstantSerializer.INSTANCE);
k.addDefaultSerializer(ZoneId.class, ZoneIdSerializer.INSTANCE);
// Add non-cloning serializers for all immutable types bellow
k.addDefaultSerializer(UUID.class, UUIDSerializer.INSTANCE);
k.addDefaultSerializer(URI.class, URISerializer.INSTANCE);
if (isObjectSerializer) {
// To avoid monotonic increase of memory use, due to reference tracking, we must
// reset kryo after each use.
k.setAutoReset(true);
} else {
// For performance reasons, and to avoid memory use, assume documents do not
// require object graph serialization with duplicate or recursive references
k.setReferences(false);
}
return k;
}
}
代码示例来源:origin: vmware/xenon
k.setDefaultSerializer(VersionFieldSerializer.class);
k.setCopyReferences(false);
k.setDefaultSerializer(FieldNullifyingVersionFieldSerializer.class);
} else {
代码示例来源:origin: com.vmware.xenon/xenon-common
private static Kryo createKryo(boolean isObjectSerializer) {
Kryo k = new Kryo();
// handle classes with missing default constructors
k.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
// supports addition of fields if the @since annotation is used
k.setDefaultSerializer(VersionFieldSerializer.class);
if (!isObjectSerializer) {
// For performance reasons, and to avoid memory use, assume documents do not
// require object graph serialization with duplicate or recursive references
k.setReferences(false);
} else {
// To avoid monotonic increase of memory use, due to reference tracking, we must
// reset after each use.
k.setAutoReset(true);
}
k.register(ExampleServiceState.class, EXAMPLE_SERVICE_CLASS_ID);
HashMap<String, String> map = new HashMap<>();
k.register(map.getClass());
return k;
}
代码示例来源:origin: vmware/xenon
private static Kryo createKryo(boolean isObjectSerializer) {
Kryo k = new Kryo();
// handle classes with missing default constructors
k.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
// supports addition of fields if the @since annotation is used
k.setDefaultSerializer(VersionFieldSerializer.class);
if (!isObjectSerializer) {
// For performance reasons, and to avoid memory use, assume documents do not
// require object graph serialization with duplicate or recursive references
k.setReferences(false);
} else {
// To avoid monotonic increase of memory use, due to reference tracking, we must
// reset after each use.
k.setAutoReset(true);
}
k.register(ExampleServiceState.class, EXAMPLE_SERVICE_CLASS_ID);
HashMap<String, String> map = new HashMap<>();
k.register(map.getClass());
return k;
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
kryo.setInstantiatorStrategy(new CubaInstantiatorStrategy());
if (onlySerializable) {
kryo.setDefaultSerializer(CubaFieldSerializer.class);
代码示例来源:origin: mbrlabs/Mundus
public KryoManager() {
// setup kryo
kryo = new Kryo();
kryo.setDefaultSerializer(TaggedFieldSerializer.class);
kryo.getTaggedFieldSerializerConfig().setOptimizedGenerics(true);
// !!!!! DO NOT CHANGE THIS, OTHERWISE ALREADY SERIALIZED OBJECTS WILL
// BE UNREADABLE !!!!
// core stuff
kryo.register(ArrayList.class, 0);
kryo.register(Date.class, 1);
kryo.register(RegistryDescriptor.class, 2);
kryo.register(ProjectRefDescriptor.class, 3);
kryo.register(SettingsDescriptor.class, 4);
kryo.register(ProjectSettingsDescriptor.class, 5);
kryo.register(KeyboardLayout.class, 6);
kryo.register(ProjectDescriptor.class, 7);
kryo.register(SceneDescriptor.class, 8);
// basic building blocks
kryo.register(FogDescriptor.class, 9);
kryo.register(GameObjectDescriptor.class, 10);
kryo.register(BaseLightDescriptor.class, 11);
// components
kryo.register(ModelComponentDescriptor.class, 12);
kryo.register(TerrainComponentDescriptor.class, 13);
}
代码示例来源:origin: hank-whu/turbo-rpc
public KryoContext() {
kryo = new Kryo(new FastClassResolver(), new MapReferenceResolver(), new DefaultStreamFactory());
kryo.setDefaultSerializer(FastSerializer.class);
kryo.setReferences(false);
代码示例来源:origin: dremio/dremio-oss
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
kryo.setDefaultSerializer(new SerializerFactory() {
@Override
public Serializer makeSerializer(final Kryo kryo, final Class<?> type) {
内容来源于网络,如有侵权,请联系作者删除!