Throw UnsupportedOperationException when JsonWriter.jsonValue is not supported (#1651)
This commit is contained in:
parent
b84b2218f2
commit
26be941575
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user