### Question:
JsonWriter implements Closeable, Flushable { public final JsonWriter jsonValue(@Nullable Object value) throws IOException { if (value instanceof Map<?, ?>) { beginObject(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { Object key = entry.getKey(); if (!(key instanceof String)) { throw new IllegalArgumentException( key == null ? "Map keys must be non-null" : "Map keys must be of type String: " + key.getClass().getName()); } name(((String) key)); jsonValue(entry.getValue()); } endObject(); } else if (value instanceof List<?>) { beginArray(); for (Object element : ((List<?>) value)) { jsonValue(element); } endArray(); } else if (value instanceof String) { value(((String) value)); } else if (value instanceof Boolean) { value(((Boolean) value).booleanValue()); } else if (value instanceof Double) { value(((Double) value).doubleValue()); } else if (value instanceof Long) { value(((Long) value).longValue()); } else if (value instanceof Number) { value(((Number) value)); } else if (value == null) { nullValue(); } else { throw new IllegalArgumentException("Unsupported type: " + value.getClass().getName()); } return this; } JsonWriter(); @CheckReturnValue static JsonWriter of(BufferedSink sink); void setIndent(String indent); @CheckReturnValue final String getIndent(); final void setLenient(boolean lenient); @CheckReturnValue final boolean isLenient(); final void setSerializeNulls(boolean serializeNulls); @CheckReturnValue final boolean getSerializeNulls(); abstract JsonWriter beginArray(); abstract JsonWriter endArray(); abstract JsonWriter beginObject(); abstract JsonWriter endObject(); abstract JsonWriter name(String name); abstract JsonWriter value(@Nullable String value); abstract JsonWriter nullValue(); abstract JsonWriter value(boolean value); abstract JsonWriter value(@Nullable Boolean value); abstract JsonWriter value(double value); abstract JsonWriter value(long value); abstract JsonWriter value(@Nullable Number value); final JsonWriter value(BufferedSource source); @CheckReturnValue abstract BufferedSink valueSink(); final JsonWriter jsonValue(@Nullable Object value); final void promoteValueToName(); @CheckReturnValue final int beginFlatten(); final void endFlatten(int token); @CheckReturnValue final String getPath(); @SuppressWarnings("unchecked") @CheckReturnValue final @Nullable T tag(Class<T> clazz); final void setTag(Class<T> clazz, T value);  }### Answer:
@Test public void jsonValueIllegalTypes() throws IOException { try { factory.newWriter().jsonValue(new Object()); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat().isEqualTo("Unsupported type: java.lang.Object"); } try { factory.newWriter().jsonValue('1'); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat().isEqualTo("Unsupported type: java.lang.Character"); } Map<Integer, String> mapWrongKey = new LinkedHashMap<>(); mapWrongKey.put(1, "one"); try { factory.newWriter().jsonValue(mapWrongKey); fail(); } catch (IllegalArgumentException e) { assertThat(e) .hasMessageThat() .isEqualTo("Map keys must be of type String: java.lang.Integer"); } Map<String, String> mapNullKey = new LinkedHashMap<>(); mapNullKey.put(null, "one"); try { factory.newWriter().jsonValue(mapNullKey); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat().isEqualTo("Map keys must be non-null"); } }