Skip to content

Conversation

salsama59
Copy link
Contributor

@jyemin : Hi, this is my fix for the JIRA ticket for the issue JAVA-2589.
I hope I won't get checkstyle error again. :-)
The ticket on JIRA will be updated in order to point to this actual pull request.

@jyemin jyemin self-requested a review March 19, 2018 11:24
@jyemin jyemin self-assigned this Mar 19, 2018
Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request. It needs some work but you're on the right track.

@@ -88,6 +89,15 @@ public void toJsonShouldTakeACustomDocumentCodec() {
assertEquals("{ \"database\" : { \"name\" : \"MongoDB\" } }", customDocument.toJson(customDocumentCodec));
}

/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test like this in JsonReaderTest would be more to the point:

@Test
public void testTimestampWithUnquotedKeys() {
    String json = "{$timestamp : { t : 1234, i : 1 } }";
    bsonReader = new JsonReader(json);
    assertEquals(BsonType.TIMESTAMP, bsonReader.readBsonType());
    assertEquals(new BsonTimestamp(1234, 1), bsonReader.readTimestamp());
    assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
}

@@ -1147,7 +1147,7 @@ private BsonRegularExpression visitRegularExpressionExtendedJson(final String fi

private String readStringFromExtendedJson() {
JsonToken patternToken = popToken();
if (patternToken.getType() != JsonTokenType.STRING) {
if (patternToken.getType() != JsonTokenType.STRING && patternToken.getType() != JsonTokenType.UNQUOTED_STRING) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change casts too wide a net, as this method is called from both methods implementing "Extended JSON" and for methods implementing "Shell" mode, e.g. JsonReader#visitObjectIdConstructor, and it's not correct in the shell to do something like:

{ _id : ObjectId(5aaff8caa33024673db4cddf) }

It's also called to read values in some places, not just keys.

To address this, I think you will need to leave the current method alone and add a new method that is used only to read extended JSON keys, e.g. in JsonReader#visitTimestampExtendedJson

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the tips, however I wonder what is the best way to identify methods implementing "Shell" mode? Is it by looking for methods name built like this : visitXxxxConstructor? e.g "JsonReader#visitTimestampConstructor"

@salsama59
Copy link
Contributor Author

Hello @jyemin, sorry for my late reply and thank you for your previous advices, I think now that I have a better understanding of the Json reader. Can you please review my new commit? I've updated the Pull Request based on what you told me in your code review.
Thank you, have a nice day.

@jyemin jyemin removed their assignment Oct 22, 2019
@jyemin jyemin self-requested a review June 16, 2021 19:28
@jyemin jyemin removed their request for review July 28, 2021 22:03
@jyemin
Copy link
Collaborator

jyemin commented May 21, 2022

Merged on the command line: fa2b65c

Thanks for the contribution and apologies for the long delay.

@jyemin jyemin closed this May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants