All Questions
184 questions
0
votes
1
answer
16
views
KSP generated Moshi adapters not used in combination with Retrofit in a kotlin based SpringBoot application
I fail to get serialization to work inside a small springboot application. Read a couple of issues, guides and documentation on this. But still fail to get this to work.
I use moshi for JSON ...
0
votes
1
answer
169
views
How to deserialize JSON enums in case insensitive way using Moshi library?
The sample source JSON object is defined as:
{
"source": "WIFI"
}
However, the value can be lowercase and when it does, I get following error.
Exception in thread "main&...
1
vote
1
answer
183
views
How do I deserialize a string within a moshi object as its own moshi object?
I have a JSON object (that I can't change) that passes some data like so:
{
"title": "foo",
"actions": "[
{
\"label\": \"Hello\"
...
0
votes
1
answer
777
views
Android How to convert this JSON into object of data class with Moshi Kotlin?
There is a Json file which is put to val fileInString: String. This string looks simplistically like this.
{
"groups": 2,
"group1": [
{
"word": "test11",
"...
0
votes
1
answer
97
views
Parse json with moshi where one of the fields is polymorphic
I want to parse the following JSON API response into the list of objects. As you can see, the field "record" is polymorphic.
[
{
"t_id": "638975A6-3E5A-4D38-82A0-...
-1
votes
1
answer
123
views
My API call isn't working and my app return me "Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $ solution"
Hi I'm currently working on a android app (android studio) for a class and i need to make API calls i followed some tutorials (android developper and some on YT). From these tutorial i learned to use ...
1
vote
1
answer
2k
views
Using Moshi in Kotlin (Android), Moshi.adapter() signatures seem to differ from the docs
My build.gradle dependencies (for a non-main Android Studio module):
dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
...
1
vote
1
answer
406
views
Moshi: Problems serializing List<MyClass>
I'm migrating Gson to Moshi, and I'm having problems serializing List<object>. I have no problem with "plain" objects, but with Lists.
I have a class ImageDTO (including a Moshi ...
0
votes
1
answer
2k
views
Android Kotlin Moshi: Custom adapter for Moshi not working
I have a json than can have two possible values
{"school.name": "A school name"}
or
{"name": "Another school name"}
And I have a common "College" ...
0
votes
2
answers
636
views
Moshi: How to Deserialize JSON with a mix of fixed and dynamic properties
For a JSON like this consider the properties other than attributes are dynamic:
"records": [
{
"attributes": {
"type": "...",
"url": ...
-1
votes
1
answer
645
views
How to convert a JSON array of mixed types using moshi and kotlin
Iam unable to convert this Json, keep getting the following error: com.squareup.moshi.JsonDataException: Expected a string but was BEGIN_OBJECT at path
{"summary": {
"rows": [
...
1
vote
0
answers
410
views
Converting Json to data class inside sealed class in Kotlin
I have this API Response
{
"id": 45,
"name": "Bill",
"status": "Alive",
}
the status prop can have three possible results: Alive, Dead and ...
2
votes
0
answers
42
views
How to handle rubbish data in Moshi
I do have a json:
{
"items":[
{
"id":"0000301553526",
"values":{
"name":{
"value":{
...
1
vote
1
answer
499
views
Kotlin Moshi adapter return null when library throw JsonDataException
We are using old backend. Sometimes list of objects is returned when contract says it should be text (and other ways).
How/where can we handle JsonDataException Expected a string but was BEGIN_OBJECT ...
2
votes
1
answer
1k
views
Parse JSON string to a list of objects in Kotlin Android (MOSHI?)
In my app, I'm using Retrofit to get the data from API (with flights data). I want to obatin List< Itinerary > from JSON, but the problem is that it is badly formatted, and I'm getting the ...
2
votes
1
answer
440
views
Moshi can't deserialize Map with List of values, returns LinkedHashTreeMap instead of value's class instance
Can't deserialize json to this structure: Map<String, List<SomeClass>>
I can deserialize to Map<String, SomeClass> like this:
ParameterizedType type = Types.newParameterizedType(Map....
0
votes
1
answer
459
views
Can't perform polymorphic deserialization of nested collections using Moshi PolymorphicJsonAdapterFactory
Complex nested Data types won't deserialize to intended classes using a standard approach.
As of now, I have this working code, which deserializes json to Map<String, ? extends T> structure:
...
1
vote
1
answer
884
views
Moshi Retrofit Android Json Parsing -Expected a string but was BEGIN_ARRAY at path $
I'm trying to parse some Json data into a kotlin data class but I'm getting the exception from the Api call: Expected a string but was BEGIN_ARRAY at path $.
I have no idea what is the cause of this ...
0
votes
1
answer
469
views
How to handle JSON with multiple values and Moshi
When communicating with some APIs, it can happen that the JSON body may have duplicate fields which can cause the following error:
com.squareup.moshi.JsonDataException: Multiple values for 'name' at $....
1
vote
2
answers
507
views
json converter error = moshi Expected a string but was BEGIN_OBJECT at path
How to config Moshi so that below field2 from JSON
will be converted to String "{"subfield21":"asdf","subfield22":"1234"}"
in code MyData.field2
JSON:
...
3
votes
1
answer
886
views
Kotlin Android Room handle empty list of objects in Moshi TypeConverter
I inherited an Android project where I had to rebase the rxJava code to a more pure Kotlin centric code base with a MVVM design pattern. Given my inexperience, along with lots of head scratching and ...
5
votes
1
answer
2k
views
How to specify a different name for json key while using Retrofit + Moshi
I need to make a POST request to my backend with following json:
{
start_time: 123456789
}
I have created the below data class for the body in Retrofit request:
data class MyRequestBody(
@...
1
vote
0
answers
411
views
Moshi Codegen take longer time since it uses reflection(aka."Class.classForName") to create the generated adapter. Is there a way to avoid this?
Adapters generated via codegen cannot be added in the Moshi.Builder().add(Type, JsonAdapter). So moshi doesn't know how to create the compile-time generated adapter.
It uses reflection to create them, ...
1
vote
1
answer
498
views
Mixed-mode stream-oriented JSON parsing with Moshi without special type adapters
In Java I want to parse a really long JSON file (an array of objects) using Moshi. I don't want to read the entire file in memory; rather I want to detect each object and then read and process each ...
4
votes
2
answers
6k
views
Moshi-JsonDataException: Required value '%s' missing at $
I was working with Moshi to pull JSON data from an API and map it to my DTO Data classes when I encountered this error:
FATAL EXCEPTION: main Process: com.plcoding.weatherapp, PID: 9706
com.squareup....
1
vote
0
answers
325
views
import json library moshi causes build failure
I want to use moshi to parse json file, this is my code:
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;
import org.apache.commons.io.FileUtils;
import java.io.File;
import ...
-2
votes
1
answer
711
views
parse No Key json list with moshi in Android
What I am trying to do is to get Json response from GitHub API call of user's repository list.
response example from Github is like below.
[
{
"id": 78688034,
"node_id": &...
0
votes
1
answer
145
views
How to retrieve the list of all GitHub repositories of a person? parsing json list with no key value
I know this question has been answered at this post with same question. however, my question is the Json response by the most upvoted answer will be a json list with no key value.
(you can also check ...
0
votes
1
answer
378
views
How do I create a JSON data class for this sample
Here is the JSON sample and I need data classes for this sample.
[
{
"id": "a",
"symbol": "tiger",
"name": "Tiger&...
0
votes
1
answer
528
views
Can't receive byte array using Retrofit 2 in Kotlin
I have a DTO class using Moshi that's supposed to send and receive byte arrays[], but it only works when sending them, because when I receive then I have this exception.
com.squareup.moshi....
0
votes
2
answers
1k
views
Parsing JSON Strings with moshi and retrofit2
The API I am using responds with a JSON object nested inside a list, like so:
[
{
"name": "Seattle",
"lat": 47.6038321,
"lon": -122....
0
votes
1
answer
248
views
Serialize class with abstract parameter to JSON
I have 3 classes:
GameResultList which is basically ArrayList with some helper methods in it
GameResult with an abstract value gameMode
GameMode
public class GameResultList extends ArrayList<...
8
votes
0
answers
1k
views
Moshi: How to provide adapter for PolymorphicJsonAdapterFactory.withFallbackJsonAdapter while configuring Moshi.Builder
I'm trying to use PolymorphicJsonAdapterFactory for JSON which provides different structure depending on type field, like below.
{
"notifications": [
{
"type": "...
0
votes
1
answer
578
views
Error: "Required value 'networkOffers' missing at $" For Android
I keep getting this Error call
Yet I'm not sure where to look to fix it. I have a raw JSON file in my Res Folder under the directory "Raw"
The Error is coming at my Repository
class ...
1
vote
2
answers
1k
views
Moshi : Generic Json converter for Room entity
I am trying to create a generic JSON parser String to Object with Moshi but I am not sure if I am doing it right as I am stuck in a scenario which needs to deal with List.
The idea of this interface ...
2
votes
1
answer
2k
views
com.squreup.moshi.JsonDataException: Expected a string but was NULL at path $.data.gender
I need to parse data class from server request like this:
@JsonClass(generateAdapter = true)
data class User(
@Json(name = "user_name")
val userName: String,
@Json(name = "...
0
votes
1
answer
224
views
Parsing json that has unneeded fields with Moshi
Probably a stupid question, but what is the most efficient way for Moshi to parse json which contains the fields I won't use?
For example
{
"name": "Edward",
"surname"...
2
votes
1
answer
1k
views
Kotlin + Moshi serialization of object type
I have following code in Kotlin:
sealed class ParentClass
data class ChildA(val prop: String): ParentClass()
object ChildB: ParentClass()
but when I try to serialize it into JSON with Moshi I get ...
1
vote
0
answers
162
views
Android: How to parse nested json array with different data type objects using retrofit - moshi?
I want to parse nested json using retrofit moshi. The json data i'm having is an array, inside array first element is string & second is again an array.
I don't want to parse first element in the ...
0
votes
0
answers
234
views
Most efficient way to convert bulk JSON object data into Kotlin objects?
Where sending thousands of the same type of object, with numerous properties that have descriptive names (can be long), it's super inefficient, in terms of server RAM overhead, to send them as regular ...
0
votes
1
answer
178
views
Custom attributes with Moshi Json Parser
What is Jackson's @JsonAnySetter and @JsonAnyGetter equivalent for Moshi?
Is there any way to handle custom attributes in Moshi ?
2
votes
2
answers
4k
views
What is Moshi's Equivalent of GSON's gson.fromJson() and gson.toJson()?
I am following this ROOM tutorial and at some point we need to create Type Converters for ROOM. GSON is being used to parse to and from JSON.
To achieve this we first create this general interface ...
0
votes
0
answers
145
views
Moshi: Expected a string but was BEGIN_ARRAY at path $
So I am setting up a Retrofit API call with a custom parsing file and having that file sent to a Room DB that I have set up. I have been running to a problem with the repository, where I'm getting the ...
1
vote
2
answers
829
views
Moshi fail to deserialize 0, 1 to "Boolean?"
We try to deserialize JSON field from 0, 1, null to "Boolean?"
And we have this customize Annotation:
@Retention(AnnotationRetention.RUNTIME)
@JsonQualifier
annotation class BooleanType
...
2
votes
0
answers
262
views
What return type should Retrofit interface have? How do you handle exceptions?
I'm trying to use Kotlin coroutines, with Retrofit and Moshi. But I'm confused based off the information that I'm seeing what I should be doing with my retrofit interface and how to handle the network ...
1
vote
2
answers
3k
views
Moshi serialize generic classes "Failed to find the generated JsonAdapter constructor..."
I have following class hierarchy Github Sample
interface OptionV2 {
val id: String
}
@JsonClass(generateAdapter = true)
class ImageSelectionOption(
override val id: String,
value: String,...
1
vote
2
answers
322
views
Faster JSON deserialization with huge int JSON array
I have to deserialize a Json object in Android with a huge Int Json array inside.
The schema is like:
{
"key1": "value1",
"key2": "value2",
"...
0
votes
1
answer
705
views
Parsing JSON with Increment Object Name using Moshi and Retrofit in Kotlin
I am getting a JSON via an API that looks like that.
As you can see the first object name is an increment value. How do I have to handle that variable object name in the data class or the interface ...
2
votes
0
answers
427
views
Moshi Codegen- Enum with int values
I hane an api response that I want to be represented like an enum. The problem is that api response returns integer values. Is it possible moshi handle this case without writing custom adapters on my ...
1
vote
0
answers
256
views
How do I deal with different responses using Moshi?
I get responses from websocket continiously (live), and all of them looks different, for example:
Response 1:
{
"event": "update",
"status": "...