mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Specify precedence when a subtype has multiple labels
This commit is contained in:
@@ -100,7 +100,8 @@ import javax.annotation.Nullable;
|
|||||||
*
|
*
|
||||||
* <p>If an unknown subtype is encountered when decoding, this will throw a {@link
|
* <p>If an unknown subtype is encountered when decoding, this will throw a {@link
|
||||||
* JsonDataException}. If an unknown type is encountered when encoding, this will throw an {@link
|
* JsonDataException}. If an unknown type is encountered when encoding, this will throw an {@link
|
||||||
* IllegalArgumentException}.
|
* IllegalArgumentException}. If the same subtype has multiple labels the first one is used when
|
||||||
|
* encoding.
|
||||||
*
|
*
|
||||||
* <p>If you want to specify a custom unknown fallback for decoding, you can do so via
|
* <p>If you want to specify a custom unknown fallback for decoding, you can do so via
|
||||||
* {@link #withDefaultValue(Object)}. This instance should be immutable, as it is shared.
|
* {@link #withDefaultValue(Object)}. This instance should be immutable, as it is shared.
|
||||||
|
@@ -176,6 +176,8 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
|||||||
.isEqualTo(new Success("Data!"));
|
.isEqualTo(new Success("Data!"));
|
||||||
assertThat(adapter.fromJson("{\"type\":\"error\",\"error_logs\":{\"order\":66}}"))
|
assertThat(adapter.fromJson("{\"type\":\"error\",\"error_logs\":{\"order\":66}}"))
|
||||||
.isEqualTo(new Error(Collections.<String, Object>singletonMap("order", 66d)));
|
.isEqualTo(new Error(Collections.<String, Object>singletonMap("order", 66d)));
|
||||||
|
assertThat(adapter.toJson(new Success("Data!")))
|
||||||
|
.isEqualTo("{\"type\":\"success\",\"value\":\"Data!\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void uniqueLabels() {
|
@Test public void uniqueLabels() {
|
||||||
|
Reference in New Issue
Block a user