【问题标题】:Checking retrieved data format is in JSON or Invalid format using Spring Boot使用 Spring Boot 检查检索到的数据格式是 JSON 还是无效格式
【发布时间】:2018-09-08 15:06:29
【问题描述】:

我正在尝试识别在 REST 端点中检索数据的数据格式。我打算只在 API 调用时响应具有 JSON 数据格式的请求。从检索到的标题中,我打算确定这一点。

我定义的终点就像下面的结构:

@PostMapping("/login/checkAuthorization")
  public PrivillegeResponse  checkAuthorizationAction(@RequestBody 
       PrivillegeModel privillegeObj ) 
        {
          //codes to be executed
           //giving JSON response
        }

在给出它的业务逻辑实现之前,我需要验证检索到的数据是JSON数据。实现这些功能的可能性是什么?

【问题讨论】:

    标签: json validation spring-boot


    【解决方案1】:

    对于 SpringBoot ,您需要使用 @RestController 定义类。

    要将其限制为 Json ,只需定义 consumes="application/json" 属性。

    可以参考::

    Producing and consuming custom JSON Objects in Spring RESTful services

    对于通用方法,请检查 Spring RequestMapping for controllers that produce and consume JSON

    【讨论】:

    • 感谢您的回复和回复。
    • 很高兴它有帮助!
    猜你喜欢
    • 1970-01-01
    • 2012-10-05
    • 2017-12-06
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多