繁体   English   中英

SpringBoot REST Json 对 Protobuf 的请求

[英]SpringBoot REST Json Request to Protobuf

我正在尝试将 json REST 请求转换为 protobuf 格式。

样品 JSON 输入:

{
    "id": 111,
    "name": "Anirban"
}

REST controller:

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public @ResponseBody Student handleStudent(@Valid @RequestBody Student student){
    System.out.println("Name:" + student.getName());
    System.out.println("ID:" + event.getId());
    // A service to convert student to protobuf and send to other service
    return student;
}

原型文件:

syntax = "proto3";
package student;
option java_multiple_files = true;
option java_package = "com.student.protobuf";
option java_outer_classname = "StudentOuter";

message Student {
    int32 id = 1;
    string name = 2;
}

这里我想将收到的 Student json 请求转换为 protobuf object 并发送到另一个服务。 找不到任何合适的指南。 有什么帮助吗?

You use https://gitlab.com/protobuf-tools/proto_domain_converter to convert between the Student class received from REST to the Student class generated by protobuf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM