Bug: decoders do not tolerate extra keys, fails with "Unexpected name [blah]"
alexklibisz opened this issue · comments
Describe the bug
Given a vector JSON with some additional irrelevant keys:
{ "values": [1,2,3], "extra": "junk" }
The XContentCodec
will parse the JSON, but will fail to decode the vector:
org.elasticsearch.xcontent.XContentParseException: Unexpected name [extra]
This is also true for other JSON, e.g., mappings.
Expected behavior
The decoder should ignore the extra keys and proceed to decode the JSON.
Environment (please complete the following information):
- Elastiknn version: [e.g. 7.17.0.0]
To Reproduce
This test case can be added to the XContentCodecSuite and will fail:
"fails to decode vector with extra keys in it" in {
val vec = Vec.DenseFloat.random(10)
val string = s"""{ "values": ${vec.values.asJson.noSpaces}, "extra": "junk" """
val result = decodeUnsafeFromString[Vec](string)
result shouldBe vec
}
Additional context
Add any other context about the problem here.
Just noting this for others. I'll try to fix sometime next week. Such is life with hand-coded JSON parsing.