Last active
February 15, 2021 06:12
-
-
Save ZacSweers/0ef2c5f0e3f61f82063dd8c67d75879f to your computer and use it in GitHub Desktop.
Sample bug report for Moshi
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
package test; | |
import static com.google.common.truth.Truth.assertThat; | |
import com.squareup.moshi.JsonAdapter; | |
import com.squareup.moshi.Moshi; | |
import org.junit.Test; | |
import java.io.IOException; | |
public class MoshiBugReport { | |
@Test public void test() throws IOException { | |
String json = "{\"value\":1}"; | |
Moshi moshi = new Moshi.Builder() | |
.build(); | |
JsonAdapter<ExampleClass> adapter = moshi.adapter(ExampleClass.class); | |
ExampleClass instance = adapter.fromJson(json); | |
assertThat(instance.value).isEqualTo(1); | |
assertThat(adapter.toJson(instance)).isEqualTo(json); | |
} | |
public static class ExampleClass { | |
public int value; | |
} | |
} |
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
package test | |
import com.google.common.truth.Truth.assertThat | |
import com.squareup.moshi.JsonClass | |
import com.squareup.moshi.Moshi | |
import com.squareup.moshi.adapter | |
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory | |
import org.junit.Test | |
class MoshiBugReport { | |
@Test fun test() { | |
val json = "{\"value\":1}" | |
val moshi = Moshi.Builder() | |
// Add any custom adapters here | |
.add(KotlinJsonAdapterFactory()) // Omit if using code gen | |
.build() | |
val adapter = moshi.adapter<ExampleClass>() | |
val instance = adapter.fromJson(json)!! | |
assertThat(instance.value).isEqualTo(1) | |
assertThat(adapter.toJson(instance)).isEqualTo(json) | |
} | |
@JsonClass(generateAdapter = true) | |
class ExampleClass(val value: Int) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🛑 Contrary to popular belief, commenting here is not a substitute for a bug report. Please don't.