jhunters / jprotobuf

A useful utility library for java programmer using google protobuf
Apache License 2.0
879 stars 281 forks source link

服务端反序列化父类之后,调用父类方法是否可以返回子类的结果 #120

Open wsjz opened 5 years ago

wsjz commented 5 years ago

class Father{ String type; String getType(); }

class Child extends Father{ String type; String getType(){ return type; } }

Father var = new Child().setType("Child");

类似这种情况,反序列化之后的父类调用了getType()方法后能得到子类方法返回的结果吗?

jhunters commented 5 years ago

用于子类属性,pb序列化必须 要指定到子类才可以

wsjz commented 5 years ago

用于子类属性,pb序列化必须 要指定到子类才可以

怎么指定子类呢

jhunters commented 5 years ago

ProtobufProxy.create(子类.class);

wsjz commented 5 years ago

ProtobufProxy.create(子类.class);

目前我使用的场景:使用Request类,该类里放了父类,但是对Request在服务端反序列化后只能拿到父类的信息,子类的信息没了。。。