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
0
votes
0 answers

How to convert JSON 2019-04-28T00:00:00 format to GregorianCalender in Android using Kotlin and Moshi

I have an Android App written in Kotlin, that gets data from JSON. I use Retrofit and Moshi to retrieve the data. I receive errors because Moshi does not know how to convert a date to GregorianCalendar. How can I convert the JSON date format to the…
Walt
  • 111
  • 1
  • 2
  • 12
0
votes
1 answer

How to set a default value for empty fields in Moshi

I have a model written in Kotlin, where all the fields are non-nullable. how do i set a default value for null JSON fields.
UsherBaby
  • 11
  • 1
  • 4
0
votes
1 answer

Kotlin Json Question Expected a string but was BEGIN_OBJECT at path

Trying some different methods to parse nested Json that is less than user friendly. With the logger I can see the result coming in correctly but the log shows error com.squareup.moshi.JsonDataException: Expected a string but was BEGIN_OBJECT at…
0
votes
0 answers

How to flatten polymorphic lists with Moshi deserialization

I'm trying to flatten the following Json [ { "type": 1, "field": "" }, { "type": 2, "field": "", "other_field": "" }, { "type": 3, "field": "", "list_field": [ { "type": 4, …
Sfrinz
  • 49
  • 5
0
votes
0 answers

Moshi toJSON sorts alphabetically?

Can anyone tell why moshi toJSON giving alphabetical sorted JSON string Model Class : Class { String firstName; String emailID;} Resulting JSON: { "emailID" : someMail, "firstName" : name }
DbS
  • 1
  • 1
0
votes
2 answers

Moshi adapter for annotated model

I'm currently using a Moshi adapter to convert some json raw to a given type. It works fine until I used an annotated model. I'm guessing I should add another params to my adapter beside Player::class.java but I don't know what. Here is an…
loutry
  • 3
  • 3
0
votes
2 answers

How to parse JSON with N child objects

I am trying to parse a JSON response I am receiving from an 3rd party API. The response returns a json object with N child objects. The children all conform to the same model/class, but the amount of children can change. Had it been an array of…
0
votes
1 answer

Android Moshi JsonAdapter for array's of objects

I have a set of Servlets that pass back array's of objects like text=[{"sPK":1,"sName":"foobar","cFlag":0}, {"sPK":5,"sName":"barfoo","cFlag":1}] In a java app I am using org.fasterXML.Jackson to read json and to read array's of this nature…
Nefarious
  • 458
  • 6
  • 21
0
votes
0 answers

Moshi failOnUnknown() isn't working as expected

I'm new to using Moshi and Kotlin. I was excited to see that you have the ability to fail when you hit unexpected json. The thing is, it doesn't seem to work for me. Here is my builder for Retrofit @Provides internal fun provideBuilder(gson:…
c_idle
  • 1,448
  • 4
  • 22
  • 40
0
votes
0 answers

Returning Float by Moshi Adapter

Why when I'm returning Float my fromJson isn't called class RateAdapter { @FromJson fun fromJson(json: Any): Float { return 0.5f } } But when I'm wrapping it in data class, it's called correctly? class RateAdapter { …
jakub
  • 3,576
  • 3
  • 29
  • 55
0
votes
0 answers

Can't build project after upgrading to 3.3

Sometime ago I wanted to use the new Material Components for Android So I Followed their getting-started.md instructions and also updated to android studio 3.3 canary 6, and did all the migrate to androidx. But after that I experienced some wired…
0
votes
0 answers

Moshi For parsing Youtube Search Api

I have been trying to find a tutorial for Moshi library in android java for parsing some complicated api but am unable to do so.... any help is appriciated ... Api sample Value { "kind": "youtube#searchListResponse", "etag":…
Anjani Mittal
  • 507
  • 1
  • 7
  • 19
0
votes
0 answers

pretty unsure how to deserialize JSON nested objects with moshi

having a bit of an issue deserializing from this GET call using moshi https://min-api.cryptocompare.com/data/pricemultifull?fsyms=007,1337&tsyms=EUR,USD result looks like this. { "RAW":{ //not used }, "DISPLAY":{ "1337":{ "EUR":{ …
filthy_wizard
  • 740
  • 11
  • 25
0
votes
0 answers

Kotlin Moshi Adapter not called

I'm trying to write a Moshi adapter in Kotlin that will create enums based on an integer value, and will also default to a specific enum value if it encounters an unsupported value. My adapter is never getting called, which causes the default enum…
Sky Kelsey
  • 19,192
  • 5
  • 36
  • 77
0
votes
1 answer

Error using RealmList with Moshi

Caused by: java.lang.IllegalArgumentException: Platform java.lang.Class annotated [] requires explicit JsonAdapter to be registered I get the above error when using a RealmList with Moshi. public class MenuModel implements RealmModel { …
Asim
  • 6,962
  • 8
  • 38
  • 61