-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ces-samples/java/src/main/java/dev/zacsweers/moshix/sealed/sample/java/GenericRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.zacsweers.moshix.sealed.sample.java; | ||
|
||
public record GenericRecord<T>(T value) { | ||
} |
27 changes: 27 additions & 0 deletions
27
...a/src/test/java/dev/zacsweers/moshix/sealed/sample/java/RecordJsonAdapterFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dev.zacsweers.moshix.sealed.sample.java; | ||
|
||
import com.squareup.moshi.Moshi; | ||
import com.squareup.moshi.Types; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import dev.zacsweers.moshix.records.RecordsJsonAdapterFactory; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class RecordJsonAdapterFactoryTest { | ||
|
||
private final Moshi moshi = new Moshi.Builder() | ||
.add(new RecordsJsonAdapterFactory()) | ||
.build(); | ||
|
||
@Test | ||
public void genericRecord() throws IOException { | ||
var adapter = moshi.<GenericRecord<String>>adapter(Types.newParameterizedType(GenericRecord.class, String.class)); | ||
assertThat(adapter.fromJson("{\"value\":\"Okay!\"}")) | ||
.isEqualTo(new GenericRecord<>("Okay!")); | ||
} | ||
|
||
} |