/** * Set whether to send the Java collection type for each serialized * collection. Default is "true". */ public void setSendCollectionType(boolean sendCollectionType) { this.serializerFactory.setSendCollectionType(sendCollectionType); }
/** * Set whether to allow non-serializable types as Hessian arguments * and return values. Default is "true". */ public void setAllowNonSerializable(boolean allowNonSerializable) { this.serializerFactory.setAllowNonSerializable(allowNonSerializable); }
@Override protected Serializer getDefaultSerializer(Class cl) { if (_defaultSerializer != null) { return _defaultSerializer; } return new JavaSerializer(cl); }
@SuppressWarnings("unchecked") @Override public <T> T deserialize(byte[] data, Class<T> clazz) throws Exception { UnsafeByteArrayInputStream bin = new UnsafeByteArrayInputStream(data); Hessian2Input in = new Hessian2Input(bin); in.startMessage(); Object obj = in.readObject(clazz); in.completeMessage(); in.close(); return (T) obj; }
@Override public byte[] serialize(Object obj) throws Exception { UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(); Hessian2Output out = new Hessian2Output(bos); out.startMessage(); out.writeObject(obj); out.completeMessage(); out.close(); return bos.toByteArray(); }
@Override public byte[] serialize(Object data) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Hessian2Output out = new Hessian2Output(bos); out.writeObject(data); out.flush(); return bos.toByteArray(); }
@SuppressWarnings("unchecked") @Override public <T> T deserialize(byte[] data, Class<T> clz) throws IOException { Hessian2Input input = new Hessian2Input(new ByteArrayInputStream(data)); return (T) input.readObject(clz); }
@Override public Object deserialize(final byte[] bytes, final Type returnType) throws Exception { if (null == bytes || bytes.length == 0) { return null; } ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); AbstractHessianInput input = new Hessian2Input(inputStream); input.setSerializerFactory(SERIALIZER_FACTORY); Object obj = input.readObject(); input.close(); return obj; }
/** * Specify the Hessian SerializerFactory to use. * <p>This will typically be passed in as an inner bean definition * of type {@code com.caucho.hessian.io.SerializerFactory}, * with custom bean property values applied. */ public void setSerializerFactory(@Nullable SerializerFactory serializerFactory) { this.serializerFactory = (serializerFactory != null ? serializerFactory : new SerializerFactory()); }
/** * 添加自定义SerializerFactory * * @param factory AbstractSerializerFactory */ public void addSerializerFactory(AbstractSerializerFactory factory) { SERIALIZER_FACTORY.addFactory(factory); }
@Override public byte[] serializeMulti(Object[] data) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Hessian2Output out = new Hessian2Output(bos); for(Object obj: data){ out.writeObject(obj); } out.flush(); return bos.toByteArray(); }
@Override public Object[] deserializeMulti(byte[] data, Class<?>[] classes) throws IOException { Hessian2Input input = new Hessian2Input(new ByteArrayInputStream(data)); Object[] objects = new Object[classes.length]; for (int i = 0; i < classes.length; i++) { objects[i] = input.readObject(classes[i]); } return objects; }
/** * Set whether to send the Java collection type for each serialized * collection. Default is "true". */ public void setSendCollectionType(boolean sendCollectionType) { this.serializerFactory.setSendCollectionType(sendCollectionType); }
/** * Specify the Hessian SerializerFactory to use. * <p>This will typically be passed in as an inner bean definition * of type {@code com.caucho.hessian.io.SerializerFactory}, * with custom bean property values applied. */ public void setSerializerFactory(@Nullable SerializerFactory serializerFactory) { this.serializerFactory = (serializerFactory != null ? serializerFactory : new SerializerFactory()); }
/** * Set whether to allow non-serializable types as Hessian arguments * and return values. Default is "true". */ public void setAllowNonSerializable(boolean allowNonSerializable) { this.serializerFactory.setAllowNonSerializable(allowNonSerializable); }
@Override protected Serializer getDefaultSerializer(Class cl) { if (_defaultSerializer != null) { return _defaultSerializer; } return new JavaSerializer(cl); }
/** * Set whether to send the Java collection type for each serialized * collection. Default is "true". */ public void setSendCollectionType(boolean sendCollectionType) { this.proxyFactory.getSerializerFactory().setSendCollectionType(sendCollectionType); }
/** * Set whether to allow non-serializable types as Hessian arguments * and return values. Default is "true". */ public void setAllowNonSerializable(boolean allowNonSerializable) { this.proxyFactory.getSerializerFactory().setAllowNonSerializable(allowNonSerializable); }
/** * Set whether to send the Java collection type for each serialized * collection. Default is "true". */ public void setSendCollectionType(boolean sendCollectionType) { this.proxyFactory.getSerializerFactory().setSendCollectionType(sendCollectionType); }
/** * Set whether to allow non-serializable types as Hessian arguments * and return values. Default is "true". */ public void setAllowNonSerializable(boolean allowNonSerializable) { this.proxyFactory.getSerializerFactory().setAllowNonSerializable(allowNonSerializable); }