You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe there is a bug in SmileParser#getValueAsString().
Comparing the method implementation in SmileParser
@Override
public String getValueAsString() throws IOException
{
// inlined 'getText()' for common case of having String
if (_tokenIncomplete) {
_tokenIncomplete = false;
int tb = _typeAsInt;
int type = (tb >> 5);
if (type == 2 || type == 3) { // tiny & short ASCII
return _decodeShortAsciiValue(1 + (tb & 0x3F));
}
if (type == 4 || type == 5) { // tiny & short Unicode
return _decodeShortUnicodeValue(2 + (tb & 0x3F));
}
_finishToken();
}
if (_currToken == JsonToken.VALUE_STRING) {
return _textBuffer.contentsAsString();
}
if (_currToken == null || _currToken == JsonToken.VALUE_NULL || !_currToken.isScalarValue()) {
return null;
}
return getText();
}
To the implementation in jackson-core UTF8StreamJsonParser.java
public String getValueAsString() throws IOException
{
if (_currToken == JsonToken.VALUE_STRING) {
if (_tokenIncomplete) {
_tokenIncomplete = false;
return _finishAndReturnString(); // only strings can be incomplete
}
return _textBuffer.contentsAsString();
}
if (_currToken == JsonToken.FIELD_NAME) {
return currentName();
}
return super.getValueAsString(null);
}
The output is different when invoking the two methods on tokens of type JsonToken.FIELD_NAME, whereas I would expect them to behave similarly ( returning the current token field name as a string ).
I have a fork with a simple test update that reproduces the issue and a naive fix that worked for my use case. dabe16a
The updated test fails without the change in SmileParser.java .
cowtowncoder
changed the title
SmileParser getValueAsString() FIELD_NAME bugSmileParser.getValueAsString() FIELD_NAME bug (same for CBOR, Protobuf)
Jan 4, 2025
Merged in 2.19; backported to 2.17(.4), 2.18(.3) branches since this seems like a safe fix
(not sure if there will be 2.17.4, but 2.18.3 will be released)
I believe there is a bug in
SmileParser#getValueAsString()
.Comparing the method implementation in SmileParser
To the implementation in jackson-core UTF8StreamJsonParser.java
The output is different when invoking the two methods on tokens of type JsonToken.FIELD_NAME, whereas I would expect them to behave similarly ( returning the current token field name as a string ).
I have a fork with a simple test update that reproduces the issue and a naive fix that worked for my use case.
dabe16a
The updated test fails without the change in SmileParser.java .
This came to my attention while trying to use the OpenSearch java sdk with jackson and 'application/smile' encoding. The deserialized responses from opensearch contained only null properties after switching to Smile ObjectMapper. The usage in question is here https://github.com/opensearch-project/opensearch-java/blob/main/java-client/src/main/java/org/opensearch/client/json/ObjectDeserializer.java#L179 ; but it appears the usage there is correct.
Please let me know if there's any more info or help I can provide; or if I'm misunderstanding or mistaken.
The text was updated successfully, but these errors were encountered: