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

Serialization and deserialization use classes in the wrapper #11302

Merged
merged 9 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class ClassUtils {
PRIMITIVE_WRAPPER_TYPE_MAP.put(Integer.class, int.class);
PRIMITIVE_WRAPPER_TYPE_MAP.put(Long.class, long.class);
PRIMITIVE_WRAPPER_TYPE_MAP.put(Short.class, short.class);
PRIMITIVE_WRAPPER_TYPE_MAP.put(Void.class, void.class);

Set<Class<?>> primitiveTypeNames = new HashSet<>(32);
primitiveTypeNames.addAll(PRIMITIVE_WRAPPER_TYPE_MAP.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,16 @@ private WrapResponsePack(MultipleSerialization multipleSerialization, URL url,
@Override
public byte[] pack(Object obj) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
multipleSerialization.serialize(url, serialize, actualResponseType, obj, bos);
Class<?> clz;
if (obj != null) {
clz = obj.getClass();
} else {
clz = actualResponseType;
}
multipleSerialization.serialize(url, serialize, clz, obj, bos);
return TripleCustomerProtocolWapper.TripleResponseWrapper.Builder.newBuilder()
.setSerializeType(serialize)
.setType(actualResponseType.getName())
.setType(clz.getName())
.setData(bos.toByteArray())
.build()
.toByteArray();
Expand All @@ -351,7 +357,7 @@ public Object unpack(byte[] data) throws IOException, ClassNotFoundException {
.parseFrom(data);
final String serializeType = convertHessianFromWrapper(wrapper.getSerializeType());
ByteArrayInputStream bais = new ByteArrayInputStream(wrapper.getData());
return serialization.deserialize(url, serializeType, returnClass, bais);
return serialization.deserialize(url, serializeType, wrapper.getType(), bais);
}
}

Expand Down Expand Up @@ -387,10 +393,8 @@ public byte[] pack(Object obj) throws IOException {
}
final TripleCustomerProtocolWapper.TripleRequestWrapper.Builder builder = TripleCustomerProtocolWapper.TripleRequestWrapper.Builder.newBuilder();
builder.setSerializeType(serialize);
for (String type : argumentsType) {
builder.addArgTypes(type);
}
for (Object argument : arguments) {
builder.addArgTypes(argument.getClass().getName());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
multipleSerialization.serialize(url, serialize, argument.getClass(), argument, bos);
builder.addArgs(bos.toByteArray());
Expand Down Expand Up @@ -454,7 +458,7 @@ public Object unpack(byte[] data) throws IOException, ClassNotFoundException {
ByteArrayInputStream bais = new ByteArrayInputStream(
wrapper.getArgs().get(i));
ret[i] = serialization.deserialize(url, wrapper.getSerializeType(),
actualRequestTypes[i],
wrapper.getArgTypes().get(i),
bais);
}
return ret;
Expand Down