moshi

Moshi in Android Kotlin - ENUM as MutableMap key being converted to String when deseralized

柔情痞子 提交于 2021-02-08 04:10:12
问题 I have a MutableMap<CryptoTypes, CurrentTradingInfo> that I'm wanting to save in onSaveInstanceState and was going to use Moshi to convert back and forth. CryptoTypes is an ENUM private var tickerData: MutableMap<CryptoTypes, CurrentTradingInfo> = mutableMapOf() fun convertTickerDataJson(): String { val moshi = Moshi.Builder().build() val jsonAdapter = moshi.adapter<MutableMap<CryptoTypes, CurrentTradingInfo>>(MutableMap::class.java) return jsonAdapter.toJson(tickerData) } fun

Moshi cannot parse nullable

一曲冷凌霜 提交于 2021-01-28 11:30:21
问题 Hello) Hope you can help me. Using kotlin (Retrofit2 + moshi) i getting data from "https://api.spacexdata.com/v3/launches" and parsing it. All is going fine (i getting attributes like: flight_number, mission_name), but some attributes have "null", like "mission_patch" - there are 111 objects. 109 of them have data at "mission_patch", 2 objects dont have it ("mission_patch":null). My problem: moshi cannot parse correctly attribute which contains null. if i using: data class SpaceXProperty( val

Enum parsing fails with moshi and R8

孤街醉人 提交于 2021-01-28 10:47:46
问题 I have the following dependencies: moshi-codegen: 1.10.0 kotlin: 1.4.10 Android Gradle Plugin: 4.0.1 R8 is enabled in the build. At runtime, i got the following stacktrace when Moshi tries to parse enums java.lang.AssertionError: Missing field in e.f.a.k.c.b.a at com.squareup.moshi.StandardJsonAdapters$EnumJsonAdapter.<init>(SourceFile:246) at com.squareup.moshi.StandardJsonAdapters$1.create(SourceFile:67) at com.squareup.moshi.Moshi.adapter(SourceFile:141) at com.tsystems.tpay.data.client

Enum parsing fails with moshi and R8

故事扮演 提交于 2021-01-28 10:43:40
问题 I have the following dependencies: moshi-codegen: 1.10.0 kotlin: 1.4.10 Android Gradle Plugin: 4.0.1 R8 is enabled in the build. At runtime, i got the following stacktrace when Moshi tries to parse enums java.lang.AssertionError: Missing field in e.f.a.k.c.b.a at com.squareup.moshi.StandardJsonAdapters$EnumJsonAdapter.<init>(SourceFile:246) at com.squareup.moshi.StandardJsonAdapters$1.create(SourceFile:67) at com.squareup.moshi.Moshi.adapter(SourceFile:141) at com.tsystems.tpay.data.client

Moshi - Parse unknown json keys

一个人想着一个人 提交于 2021-01-27 05:13:09
问题 How can I parse with moshi a json structure that has keys that are unknown at compile time: "foo": { "name": "hello", "bar": { "unknownKey1": { "a": "1" } }, "unknownKey2": { "b": "2" }, "unknownKeyX": { "c": "X" } }, "properties": {...} } I tried using a @FromJson adapter for JSONObject but the logs just say that the json is empty {} (where I would expect {"unknownKey1": { ... etc ...} ) class Foo { @Json(name = "name") String name; @Json(name = "bar") Bar bar; static class Bar { } } class

How to parse a json list of multiple type in Moshi

浪尽此生 提交于 2021-01-21 14:32:19
问题 Got a json list mixed with plain String and Image object like this: { "mixList": [ "string", { "imageUrl": "http://...", "height": 320, "width": 480 } ] } How to parse with Moshi? I would expect to have a List<Data> , where StringData extends Data and ImageData extends Data 回答1: I've solved this problem using Moshi with a CustomAdaptor . After a lot of research I wasn't able to find a better "out-of-the-box" solution. This solutions is in kotlin but can easily be ported to Java as well. First

How to parse a json list of multiple type in Moshi

巧了我就是萌 提交于 2021-01-21 14:31:32
问题 Got a json list mixed with plain String and Image object like this: { "mixList": [ "string", { "imageUrl": "http://...", "height": 320, "width": 480 } ] } How to parse with Moshi? I would expect to have a List<Data> , where StringData extends Data and ImageData extends Data 回答1: I've solved this problem using Moshi with a CustomAdaptor . After a lot of research I wasn't able to find a better "out-of-the-box" solution. This solutions is in kotlin but can easily be ported to Java as well. First

How to parse a json list of multiple type in Moshi

雨燕双飞 提交于 2021-01-21 14:30:52
问题 Got a json list mixed with plain String and Image object like this: { "mixList": [ "string", { "imageUrl": "http://...", "height": 320, "width": 480 } ] } How to parse with Moshi? I would expect to have a List<Data> , where StringData extends Data and ImageData extends Data 回答1: I've solved this problem using Moshi with a CustomAdaptor . After a lot of research I wasn't able to find a better "out-of-the-box" solution. This solutions is in kotlin but can easily be ported to Java as well. First

How to parse a json list of multiple type in Moshi

倾然丶 夕夏残阳落幕 提交于 2021-01-21 14:30:48
问题 Got a json list mixed with plain String and Image object like this: { "mixList": [ "string", { "imageUrl": "http://...", "height": 320, "width": 480 } ] } How to parse with Moshi? I would expect to have a List<Data> , where StringData extends Data and ImageData extends Data 回答1: I've solved this problem using Moshi with a CustomAdaptor . After a lot of research I wasn't able to find a better "out-of-the-box" solution. This solutions is in kotlin but can easily be ported to Java as well. First

Unable to create call adapter for retrofit2.Response<…>

让人想犯罪 __ 提交于 2020-12-12 12:19:19
问题 My Api: @GET("/cinema/notShownMovies") fun getNotShownMovies( @Query("token") token: String ): Response<GetMovieResponse> @JsonClass(generateAdapter = true) data class Movie( val id: Long, val name: String, val date: String, @field:Json(name = "trailer_link") val trailerLink: String?, @field:Json(name = "poster_link") val posterLink: String?, @field:Json(name = "booked_tickets") val bookedTickets: Int, @field:Json(name = "movie_year_id") val movieYearId: Int, @field:Json(name = "created_at")