我正在使用具有这个具体定义的 protobufs。
message Hash {
string category = 1;
repeated KVPair content = 2;
}
message KVPair {
string key = 1;
string value = 2;
}
Run Code Online (Sandbox Code Playgroud)
我想将它作为 JSON 与我的 spring-boot 应用程序一起发送。我将此包添加到我的 gradle 依赖项中:
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.6.1'
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下代码输出哈希生成的对象时:
@RestController
@RequestMapping("/api/crm/")
public class KVController {
private final KVService kvService;
public KVController(KVService kvService) {
this.kvService = kvService;
}
@GetMapping("kv/{category}")
public Hash getHash(@PathVariable String category) {
Hash hash = kvService.retrieve(category);
return hash;
}
}
Run Code Online (Sandbox Code Playgroud)
它抛出这个最终异常:
引起:com.fasterxml.jackson.databind.exc.InvalidDefinitionException:直接自引用导致循环(通过引用链:com.blaazha.crm.proto.Hash["unknownFields"]->com.google.protobuf.UnknownFieldSet ["defaultInstanceForType"]) 在 com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) …