Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample bug report for Moshi
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;
}
}
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
You can’t perform that action at this time.