简体   繁体   English

这是 Jackson JsonParser 中的错误,还是我做错了什么?

[英]Is this a bug in the Jackson JsonParser, or am I doing something wrong?

I'm observing what appears to be some wierd behavior with the Jackson JsonParser , specifically, capturing a correct JsonPointer while in an array.我正在观察 Jackson JsonParser的一些奇怪行为,特别是在数组中捕获正确的JsonPointer

Given the following JSON snippet:给定以下 JSON 片段:

[
    {
        "name": "a",
        "children": [
            {
                "name": "b"
            },
            {
                "name": "c"
            },
            {
                "name": "d"
            }
        ]
    },
    {
        "name": "e",
        "children": [
            {
                "name": "f"
            },
            {
                "name": "g",
                "children": [
                    {
                        "name": "h"
                    },
                    {
                        "name": "i"
                    }
                ]
            }
        ]
    },
    {
        "name": "j"
    }
]

I have a simple Kotlin function that attempts to iterate on nextToken() as follows:我有一个简单的 Kotlin function 尝试迭代nextToken()如下:

fun main()
{
    val jsonParser = jacksonObjectMapper().readTree(JSON).traverse()

    while (jsonParser.nextToken() != null)
    {
        val jsonPointer = jsonParser.parsingContext?.pathAsPointer(true) ?: continue
        val tokenName = jsonParser.currentToken.name
        println("${jsonPointer.toString().padEnd(40)} $tokenName")
    }
}

Now, here's what's strange;现在,就是奇怪的地方; the jsonPointer isn't distinguishing array indices as indicated in the output: jsonPointer不区分数组索引,如 output 所示:

                                         START_ARRAY
                                         START_OBJECT
/0/name                                  FIELD_NAME
/0/name                                  VALUE_STRING
/0/children                              FIELD_NAME
/0/children                              START_ARRAY
/0/children                              START_OBJECT
/0/children/0/name                       FIELD_NAME
/0/children/0/name                       VALUE_STRING
/0/children                              END_OBJECT
/0/children                              START_OBJECT
/0/children/0/name                       FIELD_NAME
/0/children/0/name                       VALUE_STRING
/0/children                              END_OBJECT
/0/children                              START_OBJECT
/0/children/0/name                       FIELD_NAME
/0/children/0/name                       VALUE_STRING
/0/children                              END_OBJECT
/0/children                              END_ARRAY
                                         END_OBJECT
                                         START_OBJECT
/0/name                                  FIELD_NAME
/0/name                                  VALUE_STRING
/0/children                              FIELD_NAME
/0/children                              START_ARRAY
/0/children                              START_OBJECT
/0/children/0/name                       FIELD_NAME
/0/children/0/name                       VALUE_STRING
/0/children                              END_OBJECT
/0/children                              START_OBJECT
/0/children/0/name                       FIELD_NAME
/0/children/0/name                       VALUE_STRING
/0/children/0/children                   FIELD_NAME
/0/children/0/children                   START_ARRAY
/0/children/0/children                   START_OBJECT
/0/children/0/children/0/name            FIELD_NAME
/0/children/0/children/0/name            VALUE_STRING
/0/children/0/children                   END_OBJECT
/0/children/0/children                   START_OBJECT
/0/children/0/children/0/name            FIELD_NAME
/0/children/0/children/0/name            VALUE_STRING
/0/children/0/children                   END_OBJECT
/0/children/0/children                   END_ARRAY
/0/children                              END_OBJECT
/0/children                              END_ARRAY
                                         END_OBJECT
                                         START_OBJECT
/0/name                                  FIELD_NAME
/0/name                                  VALUE_STRING
                                         END_OBJECT

The paths are always giving back an index of 0 , whether in the first or n-th element.路径总是返回0的索引,无论是在第一个还是第 n 个元素中。

Is this a bug?这是一个错误吗? Or have I somehow managed to introduce one?还是我以某种方式设法介绍了一个?

It is possible you are experiencing this issue:您可能会遇到此问题:

https://github.com/FasterXML/jackson-databind/issues/2525 https://github.com/FasterXML/jackson-databind/issues/2525

which specifically affects case of "reading" contents of a JsonNode .这特别影响“读取” JsonNode内容的情况。 Handling is fixed for 2.11 (to be released by end of 2019 or early 2020), although not patched for 2.10 yet. 2.11 的处理是固定的(将于 2019 年底或 2020 年初发布),但尚未为 2.10 打补丁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编译器中的错误或我做错了什么? - Bug in compiler or am I doing something wrong? 杰克逊(Jackson)的mixin类无法解决问题:错误或我做错了什么? - Jackson's mixin class doesn't do the trick: bug or am I doing something wrong? Path的.relativize()文档中的错误,还是我在这里公然做错了什么? - Bug in Path's .relativize() documentation or am I doing something blatantly wrong here? Cassandra:将列设置为null后的写入会随机丢失。 这是一个错误,还是我做错了什么? - Cassandra: Writes after setting a column to null are lost randomly. Is this a bug, or I am doing something wrong? Tomcat maxthreads,我做错了什么吗? - Tomcat maxthreads, am I doing something wrong? Java HashMap:JVM中的错误还是我做错了? - Java HashMap: A Bug in JVM or I am doing wrong? 我的try-catch代码块做错什么了吗? - Am I doing something wrong with my try-catch block? Fortnite Tracker API似乎无法正常运行,或者我做错了什么? - Fortnite Tracker API seems not to be working or I am doing something wrong? JPanel setColor()重复无法正常工作,或者我做错了什么? - JPanel setColor() repeatation is not working properly or am I doing something wrong? 没有命名为EntityManager的持久性提供程序-我做错了什么? - No Persistence provider for EntityManager named - I am doing something wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM