jhunters / jprotobuf

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

Map<String, Object> 字段无法成功编译 #173

Open slovx2 opened 3 years ago

slovx2 commented 3 years ago
@Protobuf
private Map<String, Object> startVariable;

我声明了如上一个字段。其中value的类型有可能是List 和 String 但无法成功编译,报错如下:

Caused by: java.lang.IllegalArgumentException: Invalid class [java.lang.String] no field use annotation @com.baidu.bjf.remoting.protobuf.annotation.Protobuf at class java.lang.String at com.baidu.bjf.remoting.protobuf.utils.ProtobufProxyUtils.fetchFieldInfos(ProtobufProxyUtils.java:107) at com.baidu.bjf.remoting.protobuf.code.AbstractCodeGenerator.(AbstractCodeGenerator.java:72) at com.baidu.bjf.remoting.protobuf.code.TemplateCodeGenerator.(TemplateCodeGenerator.java:66) at com.baidu.bjf.remoting.protobuf.ProtobufProxy.getCodeGenerator(ProtobufProxy.java:195) at com.baidu.bjf.remoting.protobuf.ProtobufProxy.create(ProtobufProxy.java:276) at com.baidu.bjf.remoting.protobuf.ProtobufProxy.create(ProtobufProxy.java:249) at com.baidu.bjf.remoting.protobuf.ProtobufProxy.create(ProtobufProxy.java:208) at com.baidu.bjf.remoting.protobuf.code.CodedConstant.computeObjectSizeNoTag(CodedConstant.java:529) at com.baidu.bjf.remoting.protobuf.code.CodedConstant.computeElementSizeNoTag(CodedConstant.java:1372) at com.baidu.bjf.remoting.protobuf.code.CodedConstant.computeElementSize(CodedConstant.java:124) at com.baidu.bjf.remoting.protobuf.MapEntryLite.computeSerializedSize(MapEntryLite.java:187) at com.baidu.bjf.remoting.protobuf.MapEntry.getSerializedSize(MapEntry.java:196) at com.google.protobuf.CodedOutputStream$OutputStreamEncoder.writeMessageNoTag(CodedOutputStream.java:2854) at com.google.protobuf.CodedOutputStream$OutputStreamEncoder.writeMessage(CodedOutputStream.java:2824) at com.baidu.bjf.remoting.protobuf.code.CodedConstant.writeToMap(CodedConstant.java:498)

请问是我用法不对吗?

我试了 @Protobuf private Map<String, String> startVariable;

没问题。

但我想让startVariable的类型更灵活一点,至少支持List,String和Map,但貌似Map<String, Object>不起作用?

jhunters commented 3 years ago

对使用上有问题, Map里不能用 Obejct,必须 是明确的对象类型