Questions tagged [moshi]

Moshi is a JSON library for Android and Java. It makes it easy to parse JSON into Java objects:

About

Moshi is a modern JSON library for Android and Java. It makes it easy to parse JSON into Java objects

Moshi has built-in support for reading and writing Java’s core data types:

  • Primitives (int, float, char...) and their boxed counterparts (Integer, Float, Character...).
  • Arrays, Collections, Lists, Sets, and Maps
  • Strings
  • Enums

Links

537 questions
2
votes
2 answers

Moshi: Failed to find the generated JsonAdapter class for class

I'm following the example in https://proandroiddev.com/getting-started-using-moshi-for-json-parsing-with-kotlin-5a460bf3935a as close as possible, but still fail to run. In my Gradle, I have plugins { id 'com.android.application' id…
Elye
  • 53,639
  • 54
  • 212
  • 474
2
votes
0 answers

Use Moshi to deserialize generic type with child that can be of different types too

I have to work with a server that sends these responses for any request: For OK: HTTP 200 { "jsonrpc": "2.0", "id": null, "result": { "data": { "exp": 1635637589, ... ... }, …
allo86
  • 946
  • 1
  • 9
  • 23
2
votes
0 answers

What return type should Retrofit interface have? How do you handle exceptions?

I'm trying to use Kotlin coroutines, with Retrofit and Moshi. But I'm confused based off the information that I'm seeing what I should be doing with my retrofit interface and how to handle the network exceptions. In my interface, should I…
SmallGrammer
  • 893
  • 9
  • 19
2
votes
1 answer

Moshi didn't recognize ArrayList data class "com.squareup.moshi.JsonDataException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $"

I practicing on Retrofit with Moshi, in this simple demo app I trying to get list of albums and log it, but I got this exception after running the app E/AndroidRuntime: FATAL EXCEPTION: main Process: com.anushka.retrofitdemo, PID: 12428 …
Dr Mido
  • 2,414
  • 4
  • 32
  • 72
2
votes
0 answers

How to migrate this class from Gson to Moshi?

I have tiny wrapper around SharedPreferences written in Kotlin. I use Gson for setting and getting not primitive types. Now I would like to migrate this class to work with Moshi, but I do not understand how to work with generics in Moshi. package…
nullproduction
  • 576
  • 3
  • 18
2
votes
0 answers

Moshi Codegen- Enum with int values

I hane an api response that I want to be represented like an enum. The problem is that api response returns integer values. Is it possible moshi handle this case without writing custom adapters on my own? Example(I want to display rating and type as…
Nikos M
  • 194
  • 6
2
votes
0 answers

Moshi. @Json annotation in parent abstract class is ignored

I have an abstract class which has an annotated property abstract class DataPoint( @Json(name="collected_at") @Iso8601Time val time: Long ) @Retention(AnnotationRetention.RUNTIME) @JsonQualifier annotation class Iso8601Time class…
Solvek
  • 5,158
  • 5
  • 41
  • 64
2
votes
0 answers

Moshi custom serializer on interface type implemented by enums

I am trying to implement a custom Moshi adapter, only for serialization, that serializes the enum constant instead of the enum type itself. interface ApiType { val id: Int } enum class Gender: ApiType { MALE { override val id: Int = 1 }, …
RoR noob
  • 337
  • 3
  • 11
2
votes
1 answer

Retrofit + Moshi custom adapter

I am struggling to understand how to convert JSON data with Moshi. I am learning Android and Kotlin and my app is supposed to load and display COVID data. The input JSON format is like this: [ { "infected": 109782, "tested": "NA", …
Anton V
  • 21
  • 2
2
votes
1 answer

Parse object of dynamic string with Moshi and Retrofit

I have a JSON like below. { "code": "success", "response": { "data": { "xyz": "abc.pdf", "abc: "efgh.pdf" } }, "message": "Files downloaded Successfully" } Inside data in the response object,…
Shihab Uddin
  • 6,699
  • 2
  • 59
  • 74
2
votes
0 answers

Unable to create converter (Kotlin, Retrofit and Moshi)

I'm having an issue with a simple GET request in Retrofit. I'm getting data from API that returns many pairs that I don't really need, so I just focused on the elements that I need to parse when it comes to this specific request. To get an idea,…
friderik
  • 117
  • 2
  • 12
2
votes
1 answer

Moshi cannot parse nullable

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",…
bboy
  • 55
  • 5
2
votes
1 answer

Moshi Custom Adapter - IllegalArgumentException: Conflicting @FromJson methods: after gradle version raised to 5.6.4 and plugin to 3.6.0

I had raised gradle version to 5.6.4 and Android Gradle plugin to 3.6.0. I have these methods in my custom Moshi adapter: @proguard.annotation.Keep public static class CustomAdapters { @FromJson @NullToNone public double…
cgr
  • 4,578
  • 2
  • 28
  • 52
2
votes
2 answers

How to parse a json string to a List with MOSHI

I'm looking to parse the below JSON: { "list": [ { "data1": "data1", "transaction": { "data2": "data2", "data3": "data3" }, "breakdowns": [ { "data4": "data4", "data5":…
Raphael M
  • 109
  • 1
  • 9
2
votes
1 answer

How to parse nested JSON object with Retrofit/Moshi

I used this CodeLabs tutorial to learn how to make an HTTP request from the Google Books API https://codelabs.developers.google.com/codelabs/kotlin-android-training-internet-data/#4 Right now, I'm trying to access a nested JSON object that the…