Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SerializerFactory when use hessian #808

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jcommon/rpc-codes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>rpc-codes</artifactId>
<version>1.6.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.xiaomi.data.push.uds.codes;

import com.alibaba.com.caucho.hessian.io.SerializerFactory;

/**
* @author zhangping17
* @date 2024/03/09
*/
public class DefaultHessian2FactoryInitializer{

private static SerializerFactory SERIALIZER_FACTORY;

public static SerializerFactory getSerializerFactory() {
if (SERIALIZER_FACTORY != null) {
return SERIALIZER_FACTORY;
}
synchronized (DefaultHessian2FactoryInitializer.class) {
if (SERIALIZER_FACTORY == null) {
SERIALIZER_FACTORY = new SerializerFactory();
}
}
return SERIALIZER_FACTORY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class HessianCodes implements ICodes {
public <T> T decode(byte[] data, Type type) {
ByteArrayInputStream is = new ByteArrayInputStream(data);
Hessian2Input hi = new Hessian2Input(is);
hi.setSerializerFactory(DefaultHessian2FactoryInitializer.getSerializerFactory());
try {
return (T) hi.readObject();
} catch (IOException e) {
Expand All @@ -53,6 +54,7 @@ public <T> T decode(byte[] data, Type type) {
public <T> byte[] encode(T t) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Hessian2Output ho = new Hessian2Output(os);
ho.setSerializerFactory(DefaultHessian2FactoryInitializer.getSerializerFactory());
try {
ho.writeObject(t);
ho.flush();
Expand Down
Loading