[英]Empty Json in Spring MVC Response Entity
我在Spring MVC应用程序中尝试用Scala替换Java,到目前为止,除了在返回正文中对case case类进行序列化之外,其他一切都工作正常。
控制器看起来像这样:
@RestController
@RequestMapping(Array("/level"))
class GameMapController {
@Autowired
private val gameMapService: GameMapService = null
@RequestMapping(value = Array("/{levelNumber}"), method = Array(RequestMethod.GET))
def getGameMap(@PathVariable levelNumber: Int): ResponseEntity[GameMap] = {
new ResponseEntity[GameMap](gameMapService.getGameMap(levelNumber), HttpStatus.OK)
}
并在正文中返回的case类如下所示:
@Document
case class GameMap(@Id id: String, levelNumber: Int, width: Int, height: Int)
我检查了GameMap对象是否设置了任何属性,但是作为响应,我仍然收到空的Json。 我错过了什么? 我是否需要为Scala类提供一些自定义反序列化功能?
这是一个很旧的线程。 但是当我自己面对同样的问题时回答这个问题。
我通过添加Scala注释@BeanProperty解决了这个问题
@Document
case class GameMap(@Id @BeanProperty id: String, @BeanProperty levelNumber: Int, @BeanProperty width: Int, @BeanProperty height: Int)
这将遵循映射器可识别的Java Bean约定创建一个getter和setters。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.