MCPcopy
hub / github.com/google/gson / beforeValue

Method beforeValue

src/main/java/com/google/gson/stream/JsonWriter.java:520–552  ·  view source on GitHub ↗

Inserts any necessary separators and whitespace before a literal value, inline array, or inline object. Also adjusts the stack to expect either a closing bracket or another element. @param root true if the value is a new array or object, the two values permitted as top-level elements.

(boolean root)

Source from the content-addressed store, hash-verified

518 * permitted as top-level elements.
519 */
520 private void beforeValue(boolean root) throws IOException {
521 switch (peek()) {
522 case EMPTY_DOCUMENT: // first in document
523 if (!lenient && !root) {
524 throw new IllegalStateException(
525 "JSON must start with an array or an object.");
526 }
527 replaceTop(JsonScope.NONEMPTY_DOCUMENT);
528 break;
529
530 case EMPTY_ARRAY: // first in array
531 replaceTop(JsonScope.NONEMPTY_ARRAY);
532 newline();
533 break;
534
535 case NONEMPTY_ARRAY: // another in array
536 out.append(',');
537 newline();
538 break;
539
540 case DANGLING_NAME: // value for name
541 out.append(separator);
542 replaceTop(JsonScope.NONEMPTY_OBJECT);
543 break;
544
545 case NONEMPTY_DOCUMENT:
546 throw new IllegalStateException(
547 "JSON must have only one top-level value.");
548
549 default:
550 throw new IllegalStateException("Nesting problem: " + stack);
551 }
552 }
553}

Callers 3

openMethod · 0.95
valueMethod · 0.95
nullValueMethod · 0.95

Calls 4

peekMethod · 0.95
replaceTopMethod · 0.95
newlineMethod · 0.95
appendMethod · 0.80

Tested by

no test coverage detected