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

Moshi parses List custom object to List that holds LinkedHashTreeMap

I have a list of custom objects that I want to parse and save in shared prefs. internal fun putObjects(key: String, item: List) { val listJson = toJson(item) edit { it.putString(key, listJson) } } internal fun getObjects(key:…
MaaAn13
  • 264
  • 5
  • 24
  • 54
3
votes
2 answers

MoshiConverterFactory is not accessable

I have added both dependencies for Moshi and converter-Moshi but yet MoshiConverterFactory is not accessible and prompting error. Why am I facing this error? I tried to use scalar-converter which worked perfectly but moshi-converter is not. I have…
Shoaib Khalid
  • 55
  • 1
  • 6
3
votes
0 answers

Moshi (Codegen) - Exclude a field or property and handle it manually without custom adapter

How to exclude or skip a JSON field without using custom adapter in Moshi and Retrofit2? I wanted to handle this particular field since the API provider has a very terrible structure. Example { "status":{ "message":"Success", …
Mihae Kheel
  • 2,441
  • 3
  • 14
  • 38
3
votes
0 answers

How to fallback on 'all' enums if values don't match in Moshi

Similar to How to fallback on a enum if values don't match in OpenAPI generator's Moshi and How to fallback on a enum if values don't match in OpenAPI generator's Moshi How can we add a custom enum adapter for moshi to support nullable or…
Jonas
  • 2,096
  • 20
  • 17
3
votes
1 answer

Moshi JSON adapter with generic type

I want to use a Moshi adapter with a generic type. Here is my generic type adapter code, fun getObjectFromJson(typeOfObject: Class, jsonString: String): T? { val moshi = Moshi.Builder().build() val jsonAdapter: JsonAdapter =…
Parag Rane
  • 179
  • 4
  • 15
3
votes
0 answers

kapt in Kotlin Multiplatform - src dirs not recognized by gradle and IDE by default

I have a Kotlin annotation processor library which generates some classes and writes them with FileSpec.builder(...) ... .build() .writeTo(processingEnv.filer) The generated files end up in…
Michał Klimczak
  • 12,674
  • 8
  • 66
  • 99
3
votes
1 answer

How to send PATCH request and change field to NULL?

I am using Retrofit 2.9.0 to send network requests: val retrofit = Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build() return retrofit.create(ApiService::class.java) and Moshi…
MaxAstin
  • 463
  • 5
  • 14
3
votes
2 answers

Why does Moshi not use my custom adapter?

We have a polymorphic behaviour, and to cater it with deserialisation, we have written a custom Moshi adapter for it. @JsonClass(generateAdapter = true) open class Field @JsonClass(generateAdapter = true) data class Field1 ( @Json(name =…
Saad Ismail
  • 1,410
  • 12
  • 18
3
votes
1 answer

Missing label with PolymorphicJsonAdapterFactory

I'm trying to use PolymorphicJsonAdapterFactory in order to obtain different types, but am always getting odd exception: Missing label for test_type My entity: @JsonClass(generateAdapter = true) data class TestResult( @Json(name = "test_type")…
3
votes
1 answer

Handling Errror Response with Moshi

in my Android app, after sending some registration credentials I get the following JSON output from the server: { "response":"successfully registered new…
ebeninki
  • 909
  • 1
  • 12
  • 34
3
votes
1 answer

Moshi + Retrofit - Handling JSON response of unknown type

I'm using Moshi and I have the following data classes @JsonClass(generateAdapter = true) data class A ( @Json(name = "_id") val id: String?, @Json(name = "b") val b: B? = null ) @JsonClass(generateAdapter = true) data class B ( …
Mostafa Saadat
  • 101
  • 1
  • 12
3
votes
0 answers

Use moshi with spring boot

How do i use Moshi with Spring boot i have set the json mapper and added the pom but i don't seems to work spring.http.converters.preferred-json-mapper=moshi com.squareup.moshi
lars1595
  • 886
  • 3
  • 12
  • 27
3
votes
1 answer

problem by moshi custom JsonAdapter for skip bad elements

i have a moshi custom json adapter for skip bad elements as follow: class SkipBadElementsListAdapter(private val elementAdapter: JsonAdapter) : JsonAdapter>() { object Factory : JsonAdapter.Factory { override fun create( …
h.kelidari
  • 800
  • 1
  • 11
  • 20
3
votes
2 answers

Moshi with kotlin generics throws No JsonAdapter for interface

Suppose I have an Interface IRunnable and two implementations Cat and Dog : interface IRunnable { fun run() } class Cat : IRunnable { override fun run() { println("cat running") } } class Dog : IRunnable { override fun run() { println("dog…
smallufo
  • 11,516
  • 20
  • 73
  • 111
3
votes
1 answer

How to Persist JSON object with JSON array inside it using Room and moshi with Kotlin

So, I have this JSON Object { "name": "News", "infos":[ { "title":"hello", "content":"this is the content", "recent":true }, { "title":"Tax", "content":"The European Commission is considering possible tax benefits", …
Ape04
  • 53
  • 7