Throw UnsupportedOperationException when JsonWriter.jsonValue is not supported (#1651)

This commit is contained in:
Marcono1234 2022-08-21 17:49:32 +02:00 committed by GitHub
parent b84b2218f2
commit 26be941575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -152,6 +152,10 @@ public final class JsonTreeWriter extends JsonWriter {
return this;
}
@Override public JsonWriter jsonValue(String value) throws IOException {
throw new UnsupportedOperationException();
}
@Override public JsonWriter nullValue() throws IOException {
put(JsonNull.INSTANCE);
return this;

View File

@ -426,10 +426,13 @@ public class JsonWriter implements Closeable, Flushable {
/**
* Writes {@code value} directly to the writer without quoting or
* escaping.
* escaping. This might not be supported by all implementations, if
* not supported an {@code UnsupportedOperationException} is thrown.
*
* @param value the literal string value, or null to encode a null literal.
* @return this writer.
* @throws UnsupportedOperationException if this writer does not support
* writing raw JSON values.
*/
public JsonWriter jsonValue(String value) throws IOException {
if (value == null) {

View File

@ -233,4 +233,14 @@ public final class JsonTreeWriterTest extends TestCase {
} catch (IllegalArgumentException expected) {
}
}
public void testJsonValue() throws IOException {
JsonTreeWriter writer = new JsonTreeWriter();
writer.beginArray();
try {
writer.jsonValue("test");
fail();
} catch (UnsupportedOperationException expected) {
}
}
}