Skip to content

Latest commit

 

History

History
45 lines (40 loc) · 2.63 KB

retrofit.md

File metadata and controls

45 lines (40 loc) · 2.63 KB

Query

What query will null and an empty string generate, respestively?

@GET("/api/v1/mydata")
suspend fun getMyData(
    @Query("key1") key1: String? = null,
    @Query("key2") key2: String? = "",
): Response<MyData>

Generated query

https://example.com/api/v1/mydata?key2=

What query will an empty collection generate?

@GET("/api/v1/mydata")
suspend fun getMyData(
    @Query("key1") key1: Set<String> = emptySet(),
    @Query("key2") key2: Set<String> = setOf("a", "b"),
): Response<MyData>

Generated query

https://example.com/api/v1/mydata?key2=a&key2=b

What happens if a key is missing or the value of a key is null in the JSON response?

If the expected type of a key's value in the JSON response is array ...

Corresponding property in data class annotated with @Serializable "foo" key is missing in JSON response "foo":null in JSON response
val foo: List<String> MissingFieldException JsonDecodingException
val foo: List<String>? MissingFieldException Success
val foo: List<String> = emptyList() Success JsonDecodingException
val foo: List<String>? = null Success Success

If the expected type of a key's value in the JSON response is string ...

Corresponding property in data class annotated with @Serializable "foo" key is missing in JSON response "foo":null in JSON response
val foo: String MissingFieldException JsonDecodingException
val foo: String? MissingFieldException Success
val foo: String = "" Success JsonDecodingException
val foo: String? = null Success Success