Created
March 30, 2017 13:41
-
-
Save icris/b63e6a4437609e0ed89b913b8e82b82b to your computer and use it in GitHub Desktop.
RxJava 2.x no longer accepts null values, as a simple workaround, an Observable<Null> can emit a Null, and it works with retrofit+Jackson when dealing with data from a web service.
This file contains hidden or 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
| import com.fasterxml.jackson.core.JsonParser | |
| import com.fasterxml.jackson.databind.DeserializationContext | |
| import com.fasterxml.jackson.databind.JsonDeserializer | |
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize | |
| /** | |
| * null | |
| * Created by icris on 2017/3/26. | |
| */ | |
| @JsonDeserialize(using = NullDeserializer::class) | |
| object Null | |
| class NullDeserializer : JsonDeserializer<Null>() { | |
| override fun deserialize(p: JsonParser?, c: DeserializationContext?) = Null | |
| override fun getNullValue(c: DeserializationContext?) = Null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment