spring 控制器 return 特定路径的 protobuf

spring controller return protobuf for specific path

我有一个控制器可以将返回的对象转换成 json 对于特定路径“/protobuf”,我希望它转换为 protobuf,我该怎么做?

@RequestMapping(
    method   = RequestMethod.POST,
    value    = { "/{version}/protobuf" },
    consumes = { MediaType.APPLICATION_OCTET_STREAM_VALUE, "application/x-protobuf" },
    produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE, "application/x-protobuf" }
)
@ResponseBody

如果我理解你想要你的方法 return protobuf 而不是 json。

你能去掉@ResponseBody吗

@RequestMapping(
    method   = RequestMethod.POST,
    value    = { "/{version}/protobuf" },
    consumes = { MediaType.APPLICATION_OCTET_STREAM_VALUE, "application/x-protobuf" },
    produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE, "application/x-protobuf" }
)