Update JSON path after promoteNameToValue - #3098
Conversation
eamonnmcmanus
left a comment
There was a problem hiding this comment.
Thanks for doing this! Just one small request.
I believe @Marcono1234 is familiar with the issues here and may want to weigh in.
| JsonReader reader = factory.create("{\"name\":\"value\"}"); | ||
| reader.beginObject(); | ||
| JsonReaderInternalAccess.INSTANCE.promoteNameToValue(reader); | ||
| assertThat(reader.nextString()).isEqualTo("name"); |
There was a problem hiding this comment.
I think this would be slightly easier to read like this:
String s1 = reader.nextString();
assertThat(s1).isEqualTo("name");
assertThat(reader.getPreviousPath()).isEqualTo("$.name");The idea being to avoid calling methods with side-effects inside assertThat. As written the difference between what's happening in the first assertion and in the second is not obvious.
There was a problem hiding this comment.
Split the assertions as requested so nextString() is no longer called inside assertThat.
|
Thanks a lot, @eamonnmcmanus 🙂 |
Map deserialization reads object keys via promoteNameToValue, which previously left pathNames unset, so errors while reading the value reported path $. instead of $.key (google#1768).
The JSON path now includes the last consumed map key, so the trailing-comma error is at $.a rather than $..
15844b5 to
232762b
Compare
Thanks a lot for this pull request! Looks good to me and I think you covered all corner cases. I am wondering though if the (Sorry for this late comment.) |
|
Thanks @Marcono1234 — you're not overlooking anything.
|
Fixes #1768.
MapTypeAdapterFactoryreads object-encoded keys throughpromoteNameToValue, which turned a property name into a value without recording it inpathNames. After the key was consumed,getPath()stayed at$., so a later parse error (for example an unterminated string value) omitted the property name.JsonReadernow records the promoted name once it is actually read, andJsonTreeReader.promoteNameToValuewrites the name into the path immediately. Duplicate-key messages therefore include$.keyas well.I already have a Google CLA on file (auto#2123).