@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } /** * Kryo requires every class to provide a zero argument constructor. For any class does not match this condition, kryo have two ways: * 1. Use JavaSerializer, * 2. Set 'kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));', StdInstantiatorStrategy can generate an instance bypassing the constructor. * * In practice, it's not possible for Dubbo users to register kryo Serializer for every customized class. So in most cases, customized classes with/without zero argument constructor will * default to the default serializer. * It is the responsibility of kryo to handle with every standard jdk classes, so we will just escape these classes. */ if (!ReflectionUtils.isJdk(type) && !type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) { if (logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } /** * Kryo requires every class to provide a zero argument constructor. For any class does not match this condition, kryo have two ways: * 1. Use JavaSerializer, * 2. Set 'kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));', StdInstantiatorStrategy can generate an instance bypassing the constructor. * * In practice, it's not possible for Dubbo users to register kryo Serializer for every customized class. So in most cases, customized classes with/without zero argument constructor will * default to the default serializer. * It is the responsibility of kryo to handle with every standard jdk classes, so we will just escape these classes. */ if (!ReflectionUtils.isJdk(type) && !type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) { if (logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
kryo.register(BitSet.class, new JavaSerializer());
m.put(Class.forName("scala.reflect.ClassTag$$anon$1"), new JavaSerializer()); m.put(Class.forName("scala.reflect.ManifestFactory$$anon$1"), new JavaSerializer()); m.put(Class.forName("org.apache.spark.internal.io.FileCommitProtocol$TaskCommitMessage"), new JavaSerializer()); m.put(Class.forName("org.apache.spark.internal.io.FileCommitProtocol$EmptyTaskCommitMessage$"), new JavaSerializer());
kryo.register(tr.getTargetClass(), new JavaSerializer()); } else {
JavaSerializer serializer = new JavaSerializer(); kryo.register(LinkedHashMultimap.class, serializer);
kryoRegistrator.register(Color.class, new JavaSerializer());
@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } if (!type.isArray() && !type.isEnum() && !ReflectUtils.checkZeroArgConstructor(type)) { if (logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } if (!type.isArray() && !ReflectionUtils.checkZeroArgConstructor(type)) { if (log.isWarnEnabled()) { log.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
public Serializer getDefaultSerializer(Class type) { if(type == null) { throw new IllegalArgumentException("type cannot be null."); } else if(!type.isArray() && !checkZeroArgConstructor(type)) { if(logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } else { return super.getDefaultSerializer(type); } } }
/** Determines if this class requires the fall-back {@code JavaSerializer}. If the class does not require any specialized Java * serialization features then null will be returned. * * @param type the type we wish to externalize * @return a {@code JavaSerializer} if the type requires more than simple externalization. */ private JavaSerializer getJavaSerializerIfRequired (Class type) { JavaSerializer javaSerializer = getCachedSerializer(type); if (javaSerializer == null && isJavaSerializerRequired(type)) { javaSerializer = new JavaSerializer(); } return javaSerializer; }
@SuppressWarnings("unchecked") @Override public <T> T readObject(byte[] bytes, Class<T> clazz) { Kryo kryo = new Kryo(); kryo.setReferences(false); kryo.register(clazz, new JavaSerializer()); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); Input input = new Input(bais); return (T) kryo.readClassAndObject(input); }
/** Determines if this class requires the fall-back {@code JavaSerializer}. If the class does not require any specialized Java * serialization features then null will be returned. * * @param type the type we wish to externalize * @return a {@code JavaSerializer} if the type requires more than simple externalization. */ private JavaSerializer getJavaSerializerIfRequired (Class type) { JavaSerializer javaSerializer = getCachedSerializer(type); if (javaSerializer == null && isJavaSerializerRequired(type)) { javaSerializer = new JavaSerializer(); } return javaSerializer; }
/** * Determines if this class requires the fall-back {@code JavaSerializer}. If the class does * not require any specialized Java serialization features then null will be returned. * * @param type the type we wish to externalize * @return a {@code JavaSerializer} if the type requires more than simple externalization. */ private JavaSerializer getJavaSerializerIfRequired (Class type) { JavaSerializer javaSerializer = getCachedSerializer(type); if (javaSerializer == null && isJavaSerializerRequired(type)) { javaSerializer = new JavaSerializer(); } return javaSerializer; }
@Override public <T> byte[] writeObject(T obj) { Kryo kryo = new Kryo(); kryo.setReferences(false); kryo.register(obj.getClass(), new JavaSerializer()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Output output = new Output(baos); kryo.writeClassAndObject(output, obj); output.flush(); output.close(); byte[] b = baos.toByteArray(); try { baos.flush(); baos.close(); } catch (IOException e) { e.printStackTrace(); } return b; }
@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } if (!type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) { if (logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } if (!type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) { if (logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } if (!type.isArray() && !ReflectionUtils.checkZeroArgConstructor(type)) { if (logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
@Override public Serializer getDefaultSerializer(Class type) { if (type == null) { throw new IllegalArgumentException("type cannot be null."); } if (!type.isArray() && !ReflectionUtils.checkZeroArgConstructor(type)) { if (logger.isWarnEnabled()) { logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance"); } return new JavaSerializer(); } return super.getDefaultSerializer(type); } }
public static <T extends Serializable> T serializeDeserialize(T object, Class<T> clazz) throws IOException, ClassNotFoundException { // Using Kyro as the default serializer in Spark Jobs Kryo kryo = new Kryo(); kryo.register(HoodieTableMetaClient.class, new JavaSerializer()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Output output = new Output(baos); kryo.writeObject(output, object); output.close(); Input input = new Input(new ByteArrayInputStream(baos.toByteArray())); T deseralizedObject = kryo.readObject(input, clazz); input.close(); return deseralizedObject; }