fix(serialize-json): allow singular name at document root
This commit is contained in:
parent
2a9a6300ef
commit
ae854cc040
|
@ -574,7 +574,10 @@ public class JsonReader extends SerializeReader<IOException, JsonReader> impleme
|
||||||
default -> {
|
default -> {
|
||||||
// If we are in an array, allow reading an in inferred name once
|
// If we are in an array, allow reading an in inferred name once
|
||||||
if (!wroteName) {
|
if (!wroteName) {
|
||||||
if (stack[stackSize - 1] == JsonScope.EMPTY_ARRAY || stack[stackSize - 1] == JsonScope.NONEMPTY_ARRAY) {
|
if (stack[stackSize - 1] == JsonScope.EMPTY_ARRAY
|
||||||
|
|| stack[stackSize - 1] == JsonScope.NONEMPTY_ARRAY
|
||||||
|
|| stack[stackSize - 1] == JsonScope.EMPTY_DOCUMENT
|
||||||
|
|| stack[stackSize - 1] == JsonScope.NONEMPTY_DOCUMENT) {
|
||||||
wroteName = true;
|
wroteName = true;
|
||||||
return heuristics.guessArrayElementName(getPath());
|
return heuristics.guessArrayElementName(getPath());
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,9 @@ public class JsonWriter extends SerializeWriter<IOException, JsonWriter> impleme
|
||||||
int context = peek();
|
int context = peek();
|
||||||
if (context != EMPTY_OBJECT && context != NONEMPTY_OBJECT) {
|
if (context != EMPTY_OBJECT && context != NONEMPTY_OBJECT) {
|
||||||
if (lenient) {
|
if (lenient) {
|
||||||
if (context != EMPTY_ARRAY && context != NONEMPTY_ARRAY) throw new IllegalStateException("Please begin an object or array before writing a name.");
|
if (context != EMPTY_ARRAY && context != NONEMPTY_ARRAY
|
||||||
|
&& context != EMPTY_DOCUMENT && context != NONEMPTY_DOCUMENT)
|
||||||
|
throw new IllegalStateException("Please begin an object or array before writing a name.");
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Please begin an object before writing a name.");
|
throw new IllegalStateException("Please begin an object before writing a name.");
|
||||||
}
|
}
|
||||||
|
@ -221,7 +223,8 @@ public class JsonWriter extends SerializeWriter<IOException, JsonWriter> impleme
|
||||||
private void writeDeferredName() throws IOException {
|
private void writeDeferredName() throws IOException {
|
||||||
if (deferredName != null) {
|
if (deferredName != null) {
|
||||||
int context = peek();
|
int context = peek();
|
||||||
if (context == EMPTY_ARRAY || context == NONEMPTY_ARRAY) {
|
if (context == EMPTY_ARRAY || context == NONEMPTY_ARRAY
|
||||||
|
|| context == EMPTY_DOCUMENT || context == NONEMPTY_DOCUMENT) {
|
||||||
if (commentUnexpectedNames) {
|
if (commentUnexpectedNames) {
|
||||||
// Write the name as a comment instead of literally
|
// Write the name as a comment instead of literally
|
||||||
comment(deferredName);
|
comment(deferredName);
|
||||||
|
|
Loading…
Reference in New Issue