549 questions
1
vote
1
answer
55
views
Parsing Streaming response from OpenAI using Retrofit and Gson/Moshi
I'm trying to parse the response from OpenAI transcription API with streaming enabled.
The request is:
curl https://api.openai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $...
0
votes
0
answers
53
views
Why does moshi codegen require @JsonClass to be only on concrete classes?
It seems perfectly possible for an annotation processor to generate json adapters for interfaces or abstract classes, at least in kotlin. Why doesn't moshi do this? There must be some use case that I ...
1
vote
1
answer
256
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
0
answers
124
views
Could not find com.squareup.moshi:moshi-kotlin-reflect:1.15.1
I'm currently facing a build failure in my Android project that uses Kotlin DSL with a version.toml file for dependency management. During the build process, I encounter multiple failures related to ...
1
vote
0
answers
97
views
Retrofit OkHttp with Moshi: Gzip Encoding Error
I'm using Retrofit with OkHttp and Moshi. I have to add the "Accept-Encoding":"gzip, deflate, br" header myself. But OkHttp adds its own "Accept-Encoding" header.
Due to ...
1
vote
1
answer
687
views
Prevent proguard/r8 from removing Kotlin synthetic default constructor
I'm using moshi which accesses the Kotlin default constructor of a class by reflection.
The class looks like this:
@JsonClass(generateAdapter = true)
data class AClassName(
val threadId: String,
...
0
votes
1
answer
115
views
Using Moshi in an extension function or injecting it via DI in Android
In Android, I am using an extension function to map a failed network response to my sealed ErrorResponse class.
@JsonClass(generateAdapter = true)
data class ErrorResponse(
@Json(name = "code&...
1
vote
1
answer
831
views
Using kotlin kotlinx serialization with generics
Hi everyone I have the following code that I use to serialize into json strings to store in shared preferences
interface Serializer {
public fun <T> serialize(data: T, type: Class<T>): ...
1
vote
1
answer
137
views
Map deserialization with moshi and retrofit
I have the below json response
{"page":2,
"results":{
"0":{
"id":1,
"name":"Jane"
},
"1":{
"...
1
vote
0
answers
50
views
Why is the "invisible" field null in GetStream.io dashboard despite setting it to false when querying users?
I'm encountering an issue with GetStream.io while querying users. Despite explicitly setting the "invisible" field to false in the user object during the query, the field remains null in the ...
1
vote
0
answers
140
views
How to create a custom Moshi JsonAdapter that returns a Map?
I'm using an API that returns the following data:
{
"ad": "Andorra",
"ae": "United Arab Emirates",
"af": "Afghanistan",
&...
0
votes
1
answer
279
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&...
0
votes
2
answers
611
views
Android Moshi Json Converter Causes kotlin.reflect.jvm.internal.KotlinReflectionInternalError
I am using Moshi as Json Converter with Retrofit in Android.
When I set minifyEnabled to true, For some API calls it works, but for others it throws this Error:
This callable does not support a ...
3
votes
0
answers
142
views
How tu suppress warnings issued by javac task
Recent version of Moshi (1.15.0) is issuing a warning
Kapt support in Moshi Kotlin Code Gen is deprecated and will be removed in 2.0. Please migrate to KSP. https://github.com/square/moshi#codegen&...
1
vote
0
answers
182
views
Not finding @com.squareup.moshi.Json <fields>; rule in official moshi proguard file. Am I missing something?
Given a simple data class
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class User(
@field:Json(name = "name")
val name: ...
1
vote
1
answer
455
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
1k
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
2
answers
861
views
Moshi Json name annotation property not working
I'm trying to use @Json(name = "Result") property to change the field name and it's not working. The result is always null from retrofit response, but if I use the actual "Result" ...
1
vote
2
answers
449
views
Cannot parse a list using Moshi
With all the posts out there about Moshi and people's confusion (including my own) about how to parse a list, I can't believe that this is this difficult. I have an object that has two nested lists. I ...
0
votes
0
answers
104
views
Why my MoshiConverterFactory is slower then GsonConverterFactory?
when I post an api, it took too many time to response
Here is my retrofit builder:
fun provideRetrofit(baseUrl: String): Retrofit = Retrofit.Builder()
.client(provideOkhttpClient())
....
1
vote
0
answers
156
views
Add custom adapter to moshi
I have an interface Data with a function called toData(). Different objects inherits from this Data.
Now I wrote an adapter which transform the result of toData() into an string
My custom adapter ...
0
votes
1
answer
119
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
128
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
0
answers
166
views
Moshi Json - Decompiled code still shows annotated name
I am trying to enable code obfuscation in my android project. I am using moshi for json operations. I am having a problem with release apk file. When I use a decompiler the @JsonClass(generateAdapter =...
1
vote
1
answer
75
views
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT in my weather App
I am trying to make an API call to open-meteo.com API each time I run my app I get the an error:
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT
I have checked several ...
1
vote
1
answer
3k
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'
...
0
votes
1
answer
293
views
Moshi - Unable to create converter for enum class for gradle 8 and upwards
An error occurs during runtime, after updating to gradle 8.1.1 from 7.4.2: "java.lang.IllegalArgumentException: Unable to create converter for class $myEnumClass Caused by: java.lang....
0
votes
1
answer
819
views
Enable R8 when using moshi-kotlin-codegen
I am trying to enable R8 for my project : https://github.com/alirezaeiii/TMDb-Compose-Playground
buildTypes {
release {
minifyEnabled true
shrinkResources true
...
0
votes
1
answer
50
views
Android AWS DynamoDB: Using AWS mapper.save with Moshi
I use an AWS DynamoDB database to store data. I'm saving a "CommunityUser" object, which class looks as follows:
class CommunityUser
{
@get:DynamoDBHashKey(attributeName = AWSTables....
1
vote
1
answer
476
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" ...
1
vote
1
answer
779
views
Moshi adapter to ignore bad elements from a polymorphic list
I have a polymorphic list of contents sent by the backend.
I use PolymorphicJsonAdapterFactory to parse it to Kotlin objects. It all works fine.
When the backend sends an element with an unknown type ...
2
votes
1
answer
1k
views
Moshi LinkedHashTreeMap class cast exception with Proguard
When proguard is enabled, after an API call with retrofit, I recieve a list of LinkedHashMapTree that causes this error:
java.lang.ClassCastException: com.squareup.moshi.LinkedHashTreeMap cannot be ...
0
votes
0
answers
61
views
API call providing null response
Note: This is done in Kotlin in Android studio.
Here is the documentation of my API:
https://www.api-football.com/documentation-v3#tag/Teams/operation/get-teams
I am trying to make a simple call to ...
0
votes
1
answer
392
views
PUT with Retrofit2 using Kotlin fails with 415 Server using Reqeust @Body Object in Android
I want to call a login api that I've been using for over 6 years, so I know the API is good. It is already in production, and used for our website, iOS app, and Android app. My current project is ...
0
votes
2
answers
724
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
vote
2
answers
211
views
Getting Expected BEGIN_OBJECT but was BEGIN_ARRAY error if API returns the empty array Instead of list in kotlin android moshi
Getting error while parsing the API response using Moshi.
Sample Reponses:
Expected API response
{"itemsValues":[{"Id":"567"},{"Id":"678"}]}
If list ...
-1
votes
1
answer
694
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
460
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 ...
15
votes
6
answers
11k
views
R8 full mode throws class cast exception AGP 8.0
I recently upgraded to Android Studio Flamingo and AGP 8.0
My production builds with minfiy and shrinkResources enabled, doesn't allow retrofit to make calls. This is the error thrown.
java.lang....
0
votes
1
answer
2k
views
How to serialize a value class with moshi so it just return it's value
I hava a value classin my android project (kotlin) and I want to parse a object, that contains this value class as type for a attribute, to json.
Let's say this is my value class:
@JsonClass(...
0
votes
2
answers
1k
views
Moshi equivalent to Gson.toJson
I'm new to Moshi and I was thinking to implement it to replace my Gson lib.
Can't figure out how exactly I can convert a model class into a string in JSON format.
My model is UiGeneralCategory
I have ...
0
votes
1
answer
653
views
Android Moshi unable to apply custom adapter
My use case is that in data classes wherever I have used Boolean as type, in JSON that can either comes as double quote string ("true") or normal boolean (true)
Earlier I was using Gson &...
-1
votes
1
answer
2k
views
Retrofit android Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
I am new to Retrofit and I am having a weird problem. I am getting the following error -->
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
However when I hit the endpoint with ...
2
votes
0
answers
47
views
How to handle rubbish data in Moshi
I do have a json:
{
"items":[
{
"id":"0000301553526",
"values":{
"name":{
"value":{
...
1
vote
1
answer
539
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 ...
0
votes
0
answers
81
views
How to parse a class that extends from Arraylist with Moshi
I'm new with Moshi and I'm trying to parse the data, with Retrofit, from one class that extends an Arraylist of items and I'm getting this error:
com.squareup.moshi.JsonDataException: Expected ...
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 ...
1
vote
0
answers
816
views
com.squareup.moshi.JsonDataException: Required value 'access_token' missing at $
I try to do post request using retrofit and I use moshi to serialize but I'm not very well versed in these matters. And I am facing such an error, what is the reason for this?
error
E/AndroidRuntime: ...
0
votes
1
answer
290
views
handle kotlin coroutines withContext exceptions inside try-catch not work
I call network operations like this.
viewModelScope.launch {
try {
val data = withContext(dispatcher.io()) { homeRepository.getData() }
} catch (e: Throwable) {
val error = ...