mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 08:29:22 +08:00
@@ -74,7 +74,7 @@ internal class KotlinJsonAdapter<T>(
|
|||||||
|
|
||||||
if (values[index] !== ABSENT_VALUE) {
|
if (values[index] !== ABSENT_VALUE) {
|
||||||
throw JsonDataException(
|
throw JsonDataException(
|
||||||
"Multiple values for ${constructor.parameters[index].name} at ${reader.path}")
|
"Multiple values for '${constructor.parameters[index].name}' at ${reader.path}")
|
||||||
}
|
}
|
||||||
|
|
||||||
values[index] = binding.adapter.fromJson(reader)
|
values[index] = binding.adapter.fromJson(reader)
|
||||||
@@ -86,11 +86,11 @@ internal class KotlinJsonAdapter<T>(
|
|||||||
if (values[i] === ABSENT_VALUE && !constructor.parameters[i].isOptional) {
|
if (values[i] === ABSENT_VALUE && !constructor.parameters[i].isOptional) {
|
||||||
if (!constructor.parameters[i].type.isMarkedNullable) {
|
if (!constructor.parameters[i].type.isMarkedNullable) {
|
||||||
throw JsonDataException(
|
throw JsonDataException(
|
||||||
"Required value ${constructor.parameters[i].name} missing at ${reader.path}")
|
"Required value '${constructor.parameters[i].name}' missing at ${reader.path}")
|
||||||
}
|
}
|
||||||
values[i] = null // Replace absent with null.
|
values[i] = null // Replace absent with null.
|
||||||
} else if (values[i] == null && !constructor.parameters[i].type.isMarkedNullable) {
|
} else if (values[i] == null && !constructor.parameters[i].type.isMarkedNullable) {
|
||||||
throw JsonDataException("Non-null value ${constructor.parameters[i].name} " +
|
throw JsonDataException("Non-null value '${constructor.parameters[i].name}' " +
|
||||||
"was null at ${reader.path}")
|
"was null at ${reader.path}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ internal class KotlinJsonAdapter<T>(
|
|||||||
val binding = bindings[i]!!
|
val binding = bindings[i]!!
|
||||||
val value = values[i]
|
val value = values[i]
|
||||||
if (value == null && !binding.property.returnType.isMarkedNullable) {
|
if (value == null && !binding.property.returnType.isMarkedNullable) {
|
||||||
throw JsonDataException("Non-null value ${binding.property.name} " +
|
throw JsonDataException("Non-null value '${binding.property.name}' " +
|
||||||
"was null at ${reader.path}")
|
"was null at ${reader.path}")
|
||||||
}
|
}
|
||||||
binding.set(result, value)
|
binding.set(result, value)
|
||||||
|
@@ -133,7 +133,7 @@ class KotlinJsonAdapterTest {
|
|||||||
jsonAdapter.fromJson("""{"a":4}""")
|
jsonAdapter.fromJson("""{"a":4}""")
|
||||||
fail()
|
fail()
|
||||||
} catch(expected: JsonDataException) {
|
} catch(expected: JsonDataException) {
|
||||||
assertThat(expected).hasMessage("Required value b missing at $")
|
assertThat(expected).hasMessage("Required value 'b' missing at $")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ class KotlinJsonAdapterTest {
|
|||||||
jsonAdapter.fromJson("{\"a\":null}")
|
jsonAdapter.fromJson("{\"a\":null}")
|
||||||
fail()
|
fail()
|
||||||
} catch (expected: JsonDataException) {
|
} catch (expected: JsonDataException) {
|
||||||
assertThat(expected).hasMessage("Non-null value a was null at \$")
|
assertThat(expected).hasMessage("Non-null value 'a' was null at \$")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ class KotlinJsonAdapterTest {
|
|||||||
jsonAdapter.fromJson("{\"a\":null}")
|
jsonAdapter.fromJson("{\"a\":null}")
|
||||||
fail()
|
fail()
|
||||||
} catch (expected: JsonDataException) {
|
} catch (expected: JsonDataException) {
|
||||||
assertThat(expected).hasMessage("Non-null value a was null at \$")
|
assertThat(expected).hasMessage("Non-null value 'a' was null at \$")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ class KotlinJsonAdapterTest {
|
|||||||
jsonAdapter.fromJson("""{"a":4,"a":4}""")
|
jsonAdapter.fromJson("""{"a":4,"a":4}""")
|
||||||
fail()
|
fail()
|
||||||
} catch(expected: JsonDataException) {
|
} catch(expected: JsonDataException) {
|
||||||
assertThat(expected).hasMessage("Multiple values for a at $.a")
|
assertThat(expected).hasMessage("Multiple values for 'a' at $.a")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ class KotlinJsonAdapterTest {
|
|||||||
jsonAdapter.fromJson("""{"a":4,"b":null,"b":6}""")
|
jsonAdapter.fromJson("""{"a":4,"b":null,"b":6}""")
|
||||||
fail()
|
fail()
|
||||||
} catch(expected: JsonDataException) {
|
} catch(expected: JsonDataException) {
|
||||||
assertThat(expected).hasMessage("Multiple values for b at $.b")
|
assertThat(expected).hasMessage("Multiple values for 'b' at $.b")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user