简体   繁体   English

SpringBoot REST Json 对 Protobuf 的请求

[英]SpringBoot REST Json Request to Protobuf

I am trying to convert a json REST request to protobuf format.我正在尝试将 json REST 请求转换为 protobuf 格式。

Sample JSON input:样品 JSON 输入:

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

REST controller: 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;
}

Proto file:原型文件:

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;
}

Here I want to convert the received Student json request to protobuf object and send to another service.这里我想将收到的 Student json 请求转换为 protobuf object 并发送到另一个服务。 Couldn't find any proper guide for it.找不到任何合适的指南。 Any help?有什么帮助吗?

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 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