We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hey,
I have the following issue and maybe I am just missing something:
I want to filter out null in an enum list. It works great in Java, but fails in Kotlin.
null
The following test reproduces the "wrong" behaviour:
import com.serjltt.moshi.adapters.DefaultOnDataMismatchAdapter import com.serjltt.moshi.adapters.FilterNulls import com.squareup.moshi.Moshi import org.junit.Test class AnimalTest { enum class Animal { Dog, Cat } data class Animals( @FilterNulls val animals: List<Animal> = arrayListOf() ) @Test fun testMoshiEnumNullable() { val moshi = Moshi.Builder() .add(FilterNulls.ADAPTER_FACTORY) .add(DefaultOnDataMismatchAdapter.newFactory(Animal::class.java, null)) .add(com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory()) .build() val response = moshi.adapter(Animals::class.java).fromJson("""{"animals" : [ "Dog", "Unknown" ]}""") assert(response != null) // Gets [Dog, null] instead of just [Dog] assert(response == Animals(animals = arrayListOf(Animal.Dog))) } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hey,
I have the following issue and maybe I am just missing something:
I want to filter out
null
in an enum list. It works great in Java, but fails in Kotlin.The following test reproduces the "wrong" behaviour:
The text was updated successfully, but these errors were encountered: