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

Moshi HashMap deserializer

I don't know if it is possible to deserialise arrays into hashMap i have got json : "additionalProperties": [ { "$type": "Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities", "category": "Description", "key":…
Łukasz Woźniczka
  • 1,625
  • 3
  • 28
  • 51
5
votes
0 answers

Retrofit + Moshi - NoJsonAdapter Found

java.lang.IllegalArgumentException: No JsonAdapter for retrofit2.Call (with no annotations) Message: Unable to create converter for retrofit2.Call for method…
Cody Jones
  • 424
  • 1
  • 5
  • 16
5
votes
3 answers

How to deserialize raw JSON objects with Moshi/Retrofit

I have a Sticker class and its wrapper: @JsonClass(generateAdapter = true) class StickerDto( @Json (name = "totalAnimatedStickers") val total: Int, @Json(name = "pages") val pages: Int, @Json(name = "data") val stickers:…
andrewedgar
  • 797
  • 1
  • 12
  • 46
5
votes
1 answer

Moshi adapter creation failure: "requires explicit JsonAdapter to be registered"

var wall= ArrayList() try { val response = r.getString("response") as String val moshi = Moshi.Builder().build() val type: Type = Types.newParameterizedType( ArrayList::class.java, …
killbit
  • 77
  • 2
  • 8
5
votes
2 answers

Parsing a jsonrray into object using moshi with Retrofit and Kotlin

I am trying to parse using Moshi Library for JSON Array using Kotlin Coroutines . Code use fun retrofitIndia(baseUrl : String) : Retrofit = Retrofit.Builder() .client(clientIndia) .baseUrl(baseUrl) …
Yatin
  • 2,969
  • 9
  • 34
  • 68
5
votes
0 answers

Parse unknown JSON key with Moshi

I'm trying to parse a JSON I know almost nothing about. Example of a JSON response { "response": { "content":{ "xxxxxx": "xxxxx", "xxxxx": "xxxxxx", ...... indeterminate times } } } I tried…
mamenejr
  • 305
  • 9
  • 17
5
votes
3 answers

moshi nullable list fails with "required value"

The following works: package com.squareup.moshi.problem import com.squareup.moshi.JsonClass import com.squareup.moshi.Moshi @JsonClass(generateAdapter = true) data class Foo( val bar: String? ) fun main() { val…
ligi
  • 39,001
  • 44
  • 144
  • 244
5
votes
0 answers

Parameters about Moshi custom adapter

I am using Moshi with Kotlin. According to the README, an custom TypeAdapter may like this: class CardAdapter { @ToJson String toJson(Card card) { return card.rank + card.suit.name().substring(0, 1); } @FromJson Card fromJson(String card)…
Chenhe
  • 924
  • 8
  • 19
5
votes
1 answer

Difficulty using Moshi's Kotlin codegen

I am trying to use Moshi's Kotlin codegen to get annotation support in Kotlin. Despite following the instructions carefully in the moshi codegen documentation, the annotation JsonClass in @JsonClass(generateAdapter = true) is not recognized and I am…
rstockbridge
  • 233
  • 3
  • 11
5
votes
1 answer

Can't parse Json String with Moshi

I'm trying to parse a Json response with Moshi, the problem that I have is that the value of the key is a Json wrap on a String: {"mobile_accounts_account_showProperties":"[{\"name\": \"current\"},{\"name\": \"available\"}]"} This is my…
5
votes
1 answer

How to deserialize generic class members with moshi?

I am fetching a JSON object which contains a generic member (data can be of a few different types). The class currently looks like this: @Parcelize data class Children( @Json(name = "type") val type: String, @Json(name…
SpecialSnowflake
  • 945
  • 4
  • 16
  • 32
5
votes
1 answer

MOSHI json - Automatic convertion of property names to/from snake case

Is there any way to automatically apply naming conventions to Moshi when serializing data using Moshi? e.g. I have this class which follows Kotlin naming conventions for properties (camel case) class Player { var currentHealth: Int = 100 …
Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
5
votes
1 answer

Why does Moshi return a nullable object when parsing json with fromJson?

It is probably just me using it wrong as I am new to Kotlin and Moshi. data class InitialAppResult(val status: Int, val message: String, val baseprm: String) val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() val adapter =…
Wobbley
  • 914
  • 1
  • 10
  • 27
5
votes
1 answer

Using Moshi with multiple input fields

I have some JSON that looks like this: { "name" : "Credit Card", "code" : "AUD", "value" : 1000 } and am using Moshi to unmarshall this into a data structure like: data class Account( @Json(name = "name") val name: String, …
Craig Edwards
  • 2,118
  • 1
  • 18
  • 23
5
votes
4 answers

How to serialize ArrayList using Moshi JSON library for Android

I'm trying to convert a Java object to JSON using the Moshi library for Android. The object contains a property of type ArrayList < float[]> and I'm registering the following adapter to convert the object. Type type = Types.newParameterizedType …
AndroidGuy
  • 3,371
  • 1
  • 19
  • 21