更改 spring-data-rest 的 JSON 格式 [英] Changing the JSON format for spring-data-rest

查看:56
本文介绍了更改 spring-data-rest 的 JSON 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前 spring-data-rest 在我的 spring-boot 项目中以 HAL 格式返回 JSON.我正在使用 ember.js 前端并想使用 jsonapi (http://jsonapi.org/) 规范.

Currently spring-data-rest is returning JSON in HAL format in a spring-boot project of mine. I am using an ember.js frontend and want to use jsonapi (http://jsonapi.org/) specification.

鉴于我需要自己编写格式化程序,因为尚不存在,我该如何注册新的 JSON 格式化策略?

How might I register a new JSON formatting strategy given I will need to write the formatter myself as one does not exists yet?

推荐答案

这是自定义 Spring Data REST 生成的 HATEOAS 的方法:

This is how you can customize the HATEOAS that Spring Data REST produces:

https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.customizing-json-output

如果你需要用你自己的完全替换JSON表示,那么你可以编写和注册你自己的org.springframework.core.convert.converter

If you need to completely replace the JSON representation with your own, then you can write and register your own org.springframework.core.convert.converter

或者您在普通的旧式 @RepositoryRestController 中编写自定义 REST 端点并实现您自己的 REST 端点.(<= 我建议试试这个)

Or you write your custom REST endpoints in a plain old @RepositoryRestController and implement your own REST endpoints. (<= I suggest try this)

这篇关于更改 spring-data-rest 的 JSON 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆