java - 我在邮递员和浏览器中收到 500 错误,但控制器在调试时返回正确的对象
问题描述
我编写了 API,当通过邮递员或浏览器点击时会导致 500 错误。但是,当我调试并看到服务器没有抛出任何错误并且实际上返回了正确的响应时。我以类似方式实现的其他控制器正在返回预期结果。下面是我的控制器代码。有没有人遇到过类似的情况。请帮忙。
@CrossOrigin
@GetMapping(value="/byPatientId/{patientId}", produces = "application/json")
public List<ContactInfo> getAllContacts(@PathVariable String patientId) {
logger.info("Received request for List of ContactInfo for patientId: "+patientId);
List<ContactInfo> list =
contactInfoService.getAllContacts(patientId);
return list;
}
@CrossOrigin
@GetMapping("/byContactId/{contactId}")
public ContactInfo getContactById(@PathVariable Integer contactId) {
logger.info("Received request for ContactInfo for contactId: "+contactId);
return contactInfoService.getContactById(contactId);
}
解决方案
问题在于与返回类型对象具有 oneToMany 关系的依赖对象之一。它被设置为延迟加载,因此在将对象序列化为 JSON 时,可能存在一些问题。我通过在依赖对象之上添加“@JsonIgnore”注释来处理它。现在问题解决了。
推荐阅读
- javascript - 在 textarea 标签中输入命令时触发函数
- visual-studio - SSIS 数据查看器未正确显示
- sas - 在具有不同字符长度的变量上连接两个数据集
- javascript - 可视化自相似矩阵的最佳方法是什么
- c# - 在插件程序集中更新单个 CS 文件的过程
- opendaylight - 无法删除 ODL Web 拓扑上填充的开关
- swift - Swift 和 Go 之间的 Zlib 压缩
- mongodb - 如何在 MongoDB 聚合函数中进行 LEFT JOIN?
- python - 填写HTML表格下的输入框
- java - 循环通过期货 - 你应该先检查 isDone 吗?