mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Make error message for dangling names consistent. (#501)
This commit is contained in:
@@ -76,9 +76,12 @@ final class JsonValueWriter extends JsonWriter {
|
||||
}
|
||||
|
||||
@Override public JsonWriter endObject() throws IOException {
|
||||
if (peekScope() != EMPTY_OBJECT || deferredName != null) {
|
||||
if (peekScope() != EMPTY_OBJECT) {
|
||||
throw new IllegalStateException("Nesting problem.");
|
||||
}
|
||||
if (deferredName != null) {
|
||||
throw new IllegalStateException("Dangling name: " + deferredName);
|
||||
}
|
||||
promoteValueToName = false;
|
||||
stackSize--;
|
||||
stack[stackSize] = null;
|
||||
|
@@ -604,4 +604,16 @@ public final class JsonWriterTest {
|
||||
assertThat(expected).hasMessage("Nesting problem.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void danglingNameFails() throws IOException {
|
||||
JsonWriter writer = factory.newWriter();
|
||||
writer.beginObject();
|
||||
writer.name("a");
|
||||
try {
|
||||
writer.endObject();
|
||||
fail();
|
||||
} catch (IllegalStateException expected) {
|
||||
assertThat(expected).hasMessage("Dangling name: a");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user