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

Retrofit2 and Moshi: Send JSON without nested objects

On my code i have a data class that store some information to pass to a webservice as json body data class MyDataClass( var booleanField : Boolean = true, var stringField : String = "", var aDataField : ADataClass = ADataClass() ) where…
giozh
  • 9,868
  • 30
  • 102
  • 183
0
votes
1 answer

Moshi Date Adapter begin_object but was begin_array

I'm using the retrofit and moshi library in my project to help me connect to my backend. From there, I sent dates back but apparently, moshi can't handle dates. I've written my own JsonAdapter but now I get the…
Mout Pessemier
  • 1,665
  • 3
  • 19
  • 33
0
votes
0 answers

Assign default values to nested objects when server JSON response doesn't contain key for that in Moshi?

I'm using Moshi to parse JSON responses to JAVA objets. Problem is when the server doesn't send key-value for a nested class, moshi is assigning it to null. While assigning the default values to primitives and String etc. works, instantiating the…
Ranjan
  • 1,096
  • 10
  • 22
0
votes
0 answers

How to automatically unbox root array with moshi

The API I consume, thank to Retrofit, return a lot of json which the root level consist of a container with only a list inside of it, for example: { "data": [ ... ] } In this example the name is "data" but it may vary depending on the…
Bencri
  • 1,173
  • 1
  • 7
  • 22
0
votes
0 answers

Retrofit/Moshi EoFException with Valid ResponseBody

I'm setting up a ErrorHandler to parse the ResponseBody after an unsuccessful call and I keep getting a EoFException thrown despite passing what looks like valid JSON to the converter. Original Call to WebService public void login(final String…
rkr87
  • 85
  • 9
0
votes
1 answer

IllegalStateException("JsonReader is closed")

This code doesn't throw: override fun fromJson(reader: JsonReader): List { val result = ArrayList() reader.beginObject() while (reader.hasNext()) { result.add(MyObj(reader.nextName(),…
GuilhE
  • 11,591
  • 16
  • 75
  • 116
0
votes
1 answer

Right way to use moshi in Java+kotlin project

Currently, My android project has parts of codebase both in Java & Kotlin. We are using Moshi with retrofit. Time and again I keep getting weird problems in interoperability between java & kotlin that Moshi couldn't get through. I believe I am…
farhan patel
  • 1,490
  • 2
  • 19
  • 30
0
votes
0 answers

How to build GraphQL Request with Moshi model objects

My current project employs GraphQL. I wish to investigate Moshi as my Json parser however I am experiencing difficulties in generating my GraphQL response json This is the Json Request message format I require: { "operationName":…
Hector
  • 4,016
  • 21
  • 112
  • 211
0
votes
1 answer

Retrofit + Moshi + Kotlin = 403 Error when trying to get Json Object

I'm trying to get a JsonObject with Retrofit using Moshi to parse, but keep encountering a 403 error. I can access the request from my browser, so I'm pretty sure I'm just doing something wrong in my setup here.. object RetrofitFactory { private…
Shan
  • 541
  • 3
  • 11
0
votes
0 answers

Project fails to compile when automatically generating an adapter for a class that can contain instances of itself

It doesn't look like I can add a field with the same type as the parent class if I want to automatically generate an adapter with moshi Here is my code: @JsonClass(generateAdapter = true) class CommentModel: ListingItem() { var id: String? =…
boiledbuns
  • 95
  • 1
  • 1
  • 11
0
votes
1 answer

Base64Utils.encode does not produce valid base64 encoding

I am trying to encode a byte array in base64 before sending it over the network. The output of the encode() function below is not a valid base64 because what I read from my research was that the length of the string needs to a multiple of 4. Also,…
Dhruv Sangvikar
  • 393
  • 1
  • 7
  • 22
0
votes
0 answers

Does Moshi crash if JSON response is extended with further items?

The responses from my REST calls I parse to inline fun getJsonAdapter(): JsonAdapter { return Moshi.Builder().build().adapter(T::class.java) } and then: val jsonAdapter: JsonAdapter =…
Noam Silverstein
  • 819
  • 2
  • 12
  • 18
0
votes
2 answers

How can I convert empty objects as null with moshi and retrofit?

I am using retrofit2 + Moshi in Kotlin to connect to a server. All responses are wrapped with a result attribute. I have created a generic data class as below @JsonClass(generateAdapter = true) data class CommonResponse(val result: T?) This is…
José Carlos
  • 654
  • 6
  • 16
0
votes
2 answers

Transient with Kotlin?

Trying to display a really poorly designed JSON and running into issues. The array inside the array is not needed for my purposes so I am trying to exclude it from my response in hope it will stop throwing the errors. Ugly JSON { "id": "65", …
0
votes
2 answers

Android Kotlin Retrofit + Rxjava rest call not returning requested data

I have an Android application written in Kotlin, that gets data from an API, for now it's just a local hosted JSON file. When I'm trying to get the data, I receive the error that my list, persons, is not initialized thus persons == null and didn't…
Walt
  • 111
  • 1
  • 2
  • 12