There's a problem w/ this: ```@Retention(Annotatio...
# squarelibraries
p
There's a problem w/ this:
Copy code
@Retention(AnnotationRetention.RUNTIME)
@JsonQualifier
//@Target(AnnotationTarget.FIELD)
annotation class EmptyString

internal class StringAdapter {

    @FromJson @EmptyString
    fun fromJson(reader: JsonReader) = when (reader.peek()) {
        JsonReader.Token.BOOLEAN -> when (reader.nextBoolean()) {
            false -> null // Response was false
            else ->
                throw IllegalStateException("Non-false boolean for @JsonObjectOrFalse field")
        }
        JsonReader.Token.STRING -> ""
        else ->
            throw IllegalStateException("Non-object-non-boolean value for @JsonObjectOrFalse field")
    }

    @ToJson
    fun toJson(writer: JsonWriter, @EmptyString value: String?) {}
}
That this test fails with:
Copy code
class JsonParserTest {
    @Test
    fun testEmptyStringParser(){
        val moshi = Moshi.Builder().add(StringAdapter()).add(KotlinJsonAdapterFactory()).build()
        val nullJson = """
            { "name": false }
        """.trimIndent()

        val result = moshi.adapter<TestData>(TestData::class.java).fromJson(nullJson)!!

        assert(TestData("Hello") == result)
    }
}
com.squareup.moshi.JsonDataException: Non-null value 'name' was null at $.name
. Am I missing something?