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

pojo中类型为short的无法进行创建proto代理 #199

Closed
xktder opened this issue Oct 17, 2023 · 3 comments
Closed

pojo中类型为short的无法进行创建proto代理 #199

xktder opened this issue Oct 17, 2023 · 3 comments
Assignees
Labels

Comments

@xktder
Copy link

xktder commented Oct 17, 2023

感谢

感谢作者提供如此优秀的组件😘。

short的无法进行创建proto代理

例如我java类声明的某个属性direction short,这种在经过proto转换是无法进行转换,会抛异常,之所以这里使用的short,是由于我一套pojo实体用到里所有地方,外部通讯解析时,这个字段固定了2个字节,打解包的时候不用再判断数值长度,而库字段也固定了smallint类型,在想仍然使用一套实体的情况下能否实现。

P J%ZU~@4L47IOG(X)ODC

ava.lang.IllegalArgumentException: Type mismatch. @Protobuf required type 'Integer' but field type is 'short' of field name 'direction' on class com.baidu.bjf.remoting.protobuf.simplestring.StringTypePOJOClass

	at com.baidu.bjf.remoting.protobuf.code.AbstractCodeGenerator.checkType(AbstractCodeGenerator.java:332)
	at com.baidu.bjf.remoting.protobuf.code.TemplateCodeGenerator.initEncodeMethodTemplateVariable(TemplateCodeGenerator.java:155)
	at com.baidu.bjf.remoting.protobuf.code.TemplateCodeGenerator.getCode(TemplateCodeGenerator.java:131)
	at com.baidu.bjf.remoting.protobuf.ProtobufProxy.doCreate(ProtobufProxy.java:236)
	at com.baidu.bjf.remoting.protobuf.ProtobufProxy.create(ProtobufProxy.java:174)
	at com.baidu.bjf.remoting.protobuf.ProtobufProxy.create(ProtobufProxy.java:155)
	at com.baidu.bjf.remoting.protobuf.ProtobufProxy.create(ProtobufProxy.java:128)
	at com.baidu.bjf.remoting.protobuf.ProtobufProxy.create(ProtobufProxy.java:116)
	at com.baidu.bjf.remoting.protobuf.Any.pack(Any.java:127)
	at com.baidu.bjf.remoting.protobuf.Any.pack(Any.java:149)
	at com.baidu.bjf.remoting.protobuf.v3.any.AnyTest.encodeOriginDecodeJprotobuf(AnyTest.java:90)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

我看jprotobuf生成的idl校验是允许short,但实际检测类型的时候是通不过的

G%9{FA4ZI8MRI6A%QALMQJC
30K2H%NKSQS77VI(OBV9101

尝试

是否有什么途径可以小数值类型往上一级的数值类型进行兼容。

@jhunters jhunters self-assigned this Oct 17, 2023
@jhunters jhunters added the bug label Oct 17, 2023
@jhunters
Copy link
Owner

fixed at 2.4.20

@xktder
Copy link
Author

xktder commented Oct 18, 2023

感谢

感谢您的关注与回复。

templator子类可获取

是否可以顺便把TemplateCodeGenerator.templatorprivate更改为protected,或者提供可获取templator之所以如此是由于想继续使用您的模板代码构造器,但想后续修改部分模板值,子类获取不到templator信息

@jhunters
Copy link
Owner

收到。

@xktder xktder closed this as completed Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants