mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 07:59:21 +08:00
@@ -239,6 +239,9 @@ final class StandardJsonAdapters {
|
||||
case BOOLEAN:
|
||||
return reader.nextBoolean();
|
||||
|
||||
case NULL:
|
||||
return reader.nextNull();
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("Expected a value but was " + reader.peek()
|
||||
+ " at path " + reader.getPath());
|
||||
|
@@ -84,6 +84,17 @@ public final class ObjectAdapterTest {
|
||||
assertThat(adapter.fromJson("[0, 1]")).isEqualTo(Arrays.asList(0d, 1d));
|
||||
}
|
||||
|
||||
@Test public void fromJsonDoesNotFailOnNullValues() throws Exception {
|
||||
Map<Object, Object> emptyDelivery = new LinkedHashMap<>();
|
||||
emptyDelivery.put("address", null);
|
||||
emptyDelivery.put("items", null);
|
||||
|
||||
Moshi moshi = new Moshi.Builder().build();
|
||||
JsonAdapter<Object> adapter = moshi.adapter(Object.class);
|
||||
assertThat(adapter.fromJson("{\"address\":null, \"items\":null}"))
|
||||
.isEqualTo(emptyDelivery);
|
||||
}
|
||||
|
||||
@Test public void toJsonCoercesRuntimeTypeForCollections() throws Exception {
|
||||
Collection<String> collection = new AbstractCollection<String>() {
|
||||
@Override public Iterator<String> iterator() {
|
||||
|
Reference in New Issue
Block a user