如何de(序列化)_link,以便“ rel&quot”的价值值以元素的形式出现,_link作为嵌套的JSON

发布于 2025-02-13 11:12:13 字数 1145 浏览 0 评论 0原文

Spring Hatios最新的是将链接保留为数组而不是嵌套的JSON,并将关系名称保留为“ Rel”。我们希望“ rel”值作为儿童jsons root名称。请参阅当前和预期的行为。

当前行为:

  [
    {
        "id": "id-1",
        "name": "abc",
        "description": "abc",
        "enrollments": [
            {
                "links": [
                    {
                        "rel": "fees",
                        "id": "feesId-1",
                        "href": "xyz"
                    },
                    {
                        "rel": "rates",
                        "id": "ratesId-1",
                        "href": "abc"
                    }
                ]
            }
        ]
    }
]

预期:

[
    {
      "id": "id-1",
      "name": "abc",
      "description": "abc",
      "enrollments": [
        {
          "id": "1",
          "end_timestamp": "2025-12-31T16:06:05Z",
          "_links": {
            "rates": {
              "id": "ratesId-1",
              "href": "abc"
            },
            "fees": {
              "id": "feesId-1",
              "href": "xyz"
            }
          }
        }
      ]
    }
  ]
  

Spring hatios latest is keeping links as array rather than nested json and keeping relation name as "rel". We want "rel" value as child jsons root name. Please see the current and expected behaviour.

CURRENT BEHAVIOUR:

  [
    {
        "id": "id-1",
        "name": "abc",
        "description": "abc",
        "enrollments": [
            {
                "links": [
                    {
                        "rel": "fees",
                        "id": "feesId-1",
                        "href": "xyz"
                    },
                    {
                        "rel": "rates",
                        "id": "ratesId-1",
                        "href": "abc"
                    }
                ]
            }
        ]
    }
]

EXPECTED:

[
    {
      "id": "id-1",
      "name": "abc",
      "description": "abc",
      "enrollments": [
        {
          "id": "1",
          "end_timestamp": "2025-12-31T16:06:05Z",
          "_links": {
            "rates": {
              "id": "ratesId-1",
              "href": "abc"
            },
            "fees": {
              "id": "feesId-1",
              "href": "xyz"
            }
          }
        }
      ]
    }
  ]
  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汐鸠 2025-02-20 11:12:13

返回

Returning CollectionModel instead of List resoloved the issue in my case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文