Jackson JSON避难所 - 如何基于JSON值分配对象成员?

发布于 2025-02-09 19:28:25 字数 1224 浏览 0 评论 0原文

我有一些丑陋的json,我需要进行挑选,看起来如下:

"ContainerValues": [
                        {
                          "ParentAttribute": "QuantityContained",
                          "RowList": [
                            {
                              "Values": [
                                {
                                  "Name": "Code",
                                  "ValuesByLocale": {
                                    "en-US": "GRM"
                                  },
                                },
                                {
                                  "Name": "Value",
                                  "ValuesByLocale": {
                                    "en-US": "4.0"
                                  },
                                }
                              ],
                             
                            }
                          ],
                        }
                      ],

这只是我拥有的JSON的示例。我需要做的就是将其纳入一个看起来像以下内容的POJO:

Class POJO{
    String grmValue; // This is the "Value" for the GRM "Code" above, i.e. "4.0"
    ...
}

是否知道我如何能够根据上面使用Jackson的JSON分配GRMVALUE的价值?我开始认为我需要编写一个自定义的求职者。

I have some ugly JSON that I need to deserialize which looks like the following:

"ContainerValues": [
                        {
                          "ParentAttribute": "QuantityContained",
                          "RowList": [
                            {
                              "Values": [
                                {
                                  "Name": "Code",
                                  "ValuesByLocale": {
                                    "en-US": "GRM"
                                  },
                                },
                                {
                                  "Name": "Value",
                                  "ValuesByLocale": {
                                    "en-US": "4.0"
                                  },
                                }
                              ],
                             
                            }
                          ],
                        }
                      ],

This is just a sample of the JSON I have. All I need to do is to get this into a POJO which looks like something like the following:

Class POJO{
    String grmValue; // This is the "Value" for the GRM "Code" above, i.e. "4.0"
    ...
}

Any idea how I might be able to assign the value of grmValue based on the JSON above using Jackson? I'm starting to think I'll need to write a custom deserializer.

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

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

发布评论

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

评论(1

掀纱窥君容 2025-02-16 19:28:25

首先,您必须将数据验证为类似于JSON格式的类,然后将其转换为POJO格式。

First, you have to deserialize the data to a class similar to your JSON format, then transform it to your POJO format.

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