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
2 answers

Filter pojo properties by some pattern

I've some server response (a long one) which I've converted to POJO (by using moshi library). Eventually I have list of "Items" , each "Item" looks like follow : public class Item { private String aa; private String b; private String…
Igal
  • 4,603
  • 14
  • 41
  • 66
0
votes
2 answers

How to use a RealmObject with Moshi

I have a custom object named User, which is a RealmObject. This object also has annotations for Moshi because I plan on using this object in a retrofit call. public class User extends RealmObject { @PrimaryKey private long id; @Json(name =…
Asim
  • 6,962
  • 8
  • 38
  • 61
0
votes
1 answer

Connecting moshi to Android Studio (Kotlin)

I use Kotlin in Android Studio. I can not compile the project with the moshi library connected. https://github.com/square/moshi Tell me, what am I doing wrong ?? I can see in the console: :app:packageInstantRunResourcesDebug…
levWi
  • 121
  • 1
  • 6
0
votes
0 answers

KotlinReflectionInternalError Data Class

I received the following error when attempting to use a data class as a result type in a Retrofit service. 11-15 11:35:38.345 14693-14693/com.example.app E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.app, PID: 14693 …
Bryan
  • 14,756
  • 10
  • 70
  • 125
0
votes
2 answers

POJO field declaration, set to init value or null

In my POJO, i usually declare the fields like this class SampleModel { var field1: String? = null var field2: Int? = null } If I declare like this, I will need to check if the field is null or not. But if like…
iadcialim24
  • 3,817
  • 5
  • 21
  • 32
0
votes
0 answers

Getting Class Not Found Exception when using KotlinJsonAdapterFactory() in Moshi 1.5 with Kotlin

The problem I'm facing is a little strange because when I have a normal model class which I use as a responsebody model for retrofit 2 I get some unexpected error, suppose open class Example : RealmObject(){ @Json(name = "token") var token:…
0
votes
0 answers

Sugar ORM and Moshi conflict

I ran into a multiple inheritance problem while trying to use moshi for serialization/de-serialization and Sugar ORM for the database of my Android project. Each library expects my model (POJO) to extend their classes for them to work. I already…
Ken
  • 179
  • 10
0
votes
0 answers

Saving object relationships in Moshi

I'd like to save the relationship between two json structures while parsing them with Moshi. Lets say there exists the following situation: I would like to parse this json structure: refrigerator: { ... , manufacturer: "GE", items: [{name:…
codysehl
  • 1,555
  • 2
  • 13
  • 23
0
votes
1 answer

Android Kotlin Moshi Custom Json Adapter

Ok so i have the following Json Pojo: data class JCategory( val id: Int, val name: String, val image: String?, val color: String?, val categories: List?, val products: List? ) And…
johnny_crq
  • 4,291
  • 5
  • 39
  • 64
0
votes
2 answers

Custom Retrofit converter to nest JSON

I have a POJO that contains a single authentication token in a string variable. I need to send this to my API using the following template: { “auth” : { api_key”:”XXXX” } } I am using moshi to convert my POJOs to JSON, which…
0
votes
1 answer

Multiple adapters on Moshi

I wanted to ask for certain if this is legal in Moshi to have two adapters on one Moshi - I'm not getting errors, but I found on some devices there is a problem: Moshi moshi = new Moshi.Builder() .add(new CallLogJsonAdapter()) …
jean d'arme
  • 4,033
  • 6
  • 35
  • 70
0
votes
1 answer

Serialization of int property is presented as double?

I have a basic POJO with a property of type int. ... @Json(name = "partner_id") int partner_id = 1; ... After serialization it logs this in the JSON as: ... "partner_id":1.0 ... How can I prevent conversion to double if I wish to send partner_id…
es0329
  • 1,366
  • 1
  • 18
  • 35
0
votes
1 answer

moshi and android 2.3.3

I am having a problem when using moshi on android 2.3.3: D/PassAndroid( 1649): java.lang.IllegalArgumentException: cannot construct instances of org.ligi.passandroid.model.pass.PassImpl D/PassAndroid( 1649): at…
ligi
  • 39,001
  • 44
  • 144
  • 244
0
votes
1 answer

How to deseralize an int array into a custom class with Moshi?

I use Moshi to deserialize the following JSON file: { "display": "Video 1", "isTranslated": false, "videoSize": [ 1920, 1080 ] } ... using the following model class: public class Stream { public final String…
JJD
  • 50,076
  • 60
  • 203
  • 339
0
votes
1 answer

Get a Class literal or a Type

Is it possible to get something similar to Class>.class? I read you can't call .class because of how it works interanlly, so I was wondering if maybe using something similar to new ArrayList().getClass() might work? That one in…
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
1 2 3
35
36