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
3
votes
1 answer

Account for nullable values in Moshi

I have a class defined like this: @JsonClass(generateAdapter = true) data class CurrentWeather( @Json(name = "coord") val coordinates: Coordinates, @Json(name = "weather") val condition: List, @Json(name = "base") val base:…
Sparker0i
  • 1,787
  • 4
  • 35
  • 60
3
votes
2 answers

Unable to create @Body converter for class in Retrofit using Moshi

I'm having a problem with MoshiConverterFactory and Retrofit - I can't send POST JSON request to RestAPI, because it always results in an error. I could do it successfully using Multipart, but the API doesn't support it, so it's out of the…
friderik
  • 117
  • 2
  • 12
3
votes
1 answer

okhttp3 moshi - JsonAdapter runtime issue

I'm trying to run a sample code that uses okhttp3 to make Rest api calls. MoshiJsonConvertor.kt: import com.squareup.moshi.JsonClass import com.squareup.moshi.Moshi import okhttp3.OkHttpClient import okhttp3.Request import java.io.IOException class…
Sarav
  • 245
  • 3
  • 12
3
votes
0 answers

Moshi 1.9.1 throws java.lang.NoSuchMethodException:

im in the process of upgrading from Moshi 1.8 to 1.9.1. My Data classes are annotated to generate the Adapter: @JsonClass(generateAdapter = true) data class VersionControlResponse( val versions: List ) { ... } I wrote a…
Kitesurfer
  • 3,438
  • 2
  • 29
  • 47
3
votes
1 answer

Parse internal map from JSON in Moshi

I am trying to parse following JSON using moshi but I am unable to dynamic data like USA or UK. USA and UK are dynamic keys. { "USA": { "name": "United State of America", "code": "US" }, "UK": { "name": "United Kingdom", "code":…
user1288005
  • 890
  • 2
  • 16
  • 36
3
votes
0 answers

Handle JSON response that could be list or custom object with Moshi

I am new to Moshi and looking for a way to setup a Moshi adapter with dagger 2 to automatically create a custom Object or List based on the JSON response. The API can return either of the following 2 responses: [{ "item_type": "xyz", …
Akhil Latta
  • 1,603
  • 1
  • 22
  • 37
3
votes
1 answer

How to parse inner json string as nested class using retrofit

I have used retrofit with nested classes before, but the current api I'm tring to use has such a structure: Request body: { "Id" : "a2", "messageCode" : 1, "bigNestedClass" :…
t.m.
  • 1,430
  • 16
  • 29
3
votes
1 answer

Moshi deserialise null to empty list

I'm trying to write a null-safe List adapter that will serialize a nullable list to a non nullable object. I know you can do something like this: object { @FromJson fun fromJson(@Nullable list: List?): List { …
Nathan
  • 33
  • 3
3
votes
1 answer

java.lang.IllegalArgumentException: Unable to create @Body converter for class

Recently I switched to MoshiConverterFactory from GSONConverterFactory. Every thing s working fine except the one call. Like other API calls here also I am using @Body annotation but I am getting this error java.lang.IllegalArgumentException:…
Ayush Jain
  • 563
  • 7
  • 11
3
votes
1 answer

Json parsing with moshi

Can anyone please tell me why this is not working Model class : @JsonClass(generateAdapter = true) data class InstagramBusinessAccountResponse( val data : List ) { data class Account( @Json(name = "id") val id :…
Suyash Chavan
  • 776
  • 9
  • 20
3
votes
1 answer

Moshi Custom Adapter for generic List returns List> instead of List

(Also opened an issue here: https://github.com/square/moshi/issues/768 but was asked to open also a stackoverflow question) I am writing a generic adapter to convert a json-string with lists of enum values. The standard-adapter for enums throws an…
CitrusO2
  • 846
  • 10
  • 17
3
votes
0 answers

Moshi JsonAdapter.Factory: Same type of fields, but different String format in Json

I've exposed my problem on Moshi GitHub. Resume: how to deserialize a json into a class which have 2 fields of same type, but different JSon formats, using custom annotation for these formats? With the hint given by JakeWharton, I've successfully…
SBacquart
  • 31
  • 3
3
votes
1 answer

Moshi fails on Kotlin lazy properties

When deserializing a class with Moshi it fails on by lazy property with error: IllegalArgumentException: No JsonAdapter for interface kotlin.Lazy annotated [] So I want to tell Moshi to ignore the property. The way to ignore this is apparently to…
Greg Ennis
  • 14,917
  • 2
  • 69
  • 74
3
votes
1 answer

Moshi Custom Adapter isn't being called

TL;DR: My questions are: 1 - How can I make an Adapter for the "timestamp": 1515375392.225 to ZonedDateTime. 2 - How can I register the List adapter in the moshi object Builder if I need the moshi object to get this adapter, according to the…
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
3
votes
2 answers

Moshi: Expected a Class, ParameterizedType, or GenericArrayType, but is of type null

I have this model: class Model1 { <... other fields here ...> var attributes: Map? = null <... other fields here ...> } I expect a list of these models. Sample JSON: [ { "attributes": { "title": "New…
iadcialim24
  • 3,817
  • 5
  • 21
  • 32