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

父类与子类字段序列化顺序错误 #196

Open
tsingheng opened this issue May 18, 2023 · 2 comments
Open

父类与子类字段序列化顺序错误 #196

tsingheng opened this issue May 18, 2023 · 2 comments

Comments

@tsingheng
Copy link

tsingheng commented May 18, 2023

@ProtobufClass
public class Base {

    @Protobuf(order = 1, fieldType = FieldType.UINT32)
    private Integer code;

    @Protobuf(order = 2, fieldType = FieldType.STRING)
    private String message;

}

@ProtobufClass
public class Demo extends Base {

    @Protobuf(order = 3, fieldType = FieldType.STRING)
    private String data;

序列化Demo对象预期结果是code第一位,message第二位,data第三位,但实际结果是data在第一位,code在第二位,message在第三位

@jhunters
Copy link
Owner

不是太明白问题, pb本身是不会特别指定顺序的,他序列化解析只能是依靠 tag数值, 也就是 @protobuf注释中 的order来指定的。 也测试了你的代码生成的order 是对的

@Aliang-code
Copy link

不是太明白问题, pb本身是不会特别指定顺序的,他序列化解析只能是依靠 tag数值, 也就是 @protobuf注释中 的order来指定的。 也测试了你的代码生成的order 是对的

能否把父类字段放前面,有利于省略order定义,父类order不会被子类新增字段打乱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants