-
-
Notifications
You must be signed in to change notification settings - Fork 141
Allow exposing CBOR undefined value as JsonToken.VALUE_EMBEDDED_OBJECT #588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Fawzi Essam <[email protected]>
Defaults for 3.0 should be true, I believe, so it could take place in a separate PR |
I'm not sure if we need to touch |
@@ -113,6 +113,8 @@ public final class CBORConstants | |||
|
|||
public final static int INT_BREAK = 0xFF; | |||
|
|||
public final static int SIMPLE_VALUE_UNDEFINED = 0xF7; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a Javadoc
Good question. I don't think constant String would be any better. But somehow not setting anything does seem odd. I think we can go with that; as long as behavior is tested I think we are ok. Will add one specific suggestion on code, for clearing The only (?) concern I have is about future embedded values we might want to return, and whether |
* @since 2.20 | ||
*/ | ||
public boolean isUndefined() { | ||
return (_inputBuffer[_inputPtr - 1] & 0xFF) == SIMPLE_VALUE_UNDEFINED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmh. Not a fan of this approach but... I guess it'll do. Let's preface it by
(_currToken == JsonToken.VALUE_EMBEDDED_OBJECT || _currToken == JsonToken.VALUE_NULL)
to avoid likelihood of incorrect deterimation (binary segment ending with byte 0xF7
).
Also: not 100% sure if bounds checks would be needed.
Actually, must check that _inputBuffer
is not null
-- _releaseBuffers()
clears it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I can add that.
* | ||
* @since 2.9.6 | ||
*/ | ||
protected JsonToken _decodeUndefinedValue() throws IOException { | ||
protected JsonToken _decodeUndefinedValue() { | ||
if (CBORParser.Feature.HANDLE_UNDEFINED_AS_EMBEDDED_OBJECT.enabledIn(_formatFeatures)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add _binaryValue = null;
just as sort of documentation of intent. I know it should be cleared by nextToken()
and other places but it seems better be explicit in this particular case.
Ok I added release notes and made minor tweaks -- actually can add Javadoc too and then merge. |
@iifawzi Merged into 2.20, will merge forward into 3.x, so separate PR just needed for defaults change and unit tests (likely). |
Thanks for doing the changes, I also believe for future embedded values (SimpleValue) we need to return the value itself as null would be meaningless and unexpected, but yes, maybe we discuss it in the corresponding pr later Thank you for completing the missing points |
Hello, this PR resolves #137 by
undefined
value asJsonToken.VALUE_EMBEDDED_OBJECT
isUndefined
method that could be used for both legacy handling and with embedded objects, as an indicator if the last token parsed is undefined or not.