Problem httpGet


#1

Hello

Since this morning I have a problem.
Here is the message I got from my println

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $

I want to make it clear that yesterday everything was working well.

I already try to do a “cleanproject”

My json

[{“compteurdi”:“228”,“numero”:“Di227”,“message”:“depuis hier suite changement par ste extrflis”,“equipement”:“chaudiere vapeur”,“etat”:“6”,“demandeur”:"",“datedi”:“2017-09-29 00:00:00”},{“compteurdi”:“549”,“numero”:“Di549”,“message”:“Fauteuil cass\u00e9”,“equipement”:“Mobilier bx 201”,“etat”:“4”,“demandeur”:“patricia herv\u00e9”,“datedi”:“2018-01-09 00:00:00”}]

my httpget

http://10.0.2.2:8080/WebApi/V1/index.php?op=getdi”.httpGet().responseObject(DI.Deserializer())
{ request, response, result ->
val(disw,err) = result
println(err)
disw?.forEach { DI ->
dis.add(DI)
}
adapter = DiAdapter(dis,this )
val recyclerView = findViewById(R.id.di_recycler_view) as RecyclerView
recyclerView.layoutManager = LinearLayoutManager(this) as RecyclerView.LayoutManager?
recyclerView.adapter = adapter
}

and my DI class

data class DI(var message:String = “”,
var numero:String = “”,
var equipement:String = “”,
var datedi :String = “”,
var etat:String = “”,
var demandeur:String = “”,
var urgence:String = “”,
var probleme:String = “”,
var destinataire:String = “”,
var compteur :Int = 0,
var compteurdi :Int = 0
):Parcelable{

constructor(parcel: Parcel) : this(
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readInt(),
parcel.readInt()
) {
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(message)
parcel.writeString(numero)
parcel.writeString(equipement)
parcel.writeString(datedi)
parcel.writeString(etat)
parcel.writeString(demandeur)
parcel.writeString(urgence)
parcel.writeString(probleme)
parcel.writeString(destinataire)
parcel.writeInt(compteur)
parcel.writeInt(compteurdi)

}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<DI> {
override fun createFromParcel(parcel: Parcel): DI {
return DI(parcel)
}

override fun newArray(size: Int): Array<DI?> {
return arrayOfNulls(size)
}
}

class Deserializer:ResponseDeserializable<Array<DI>>{
override fun deserialize(content: String): Array<DI>? = Gson().fromJson(content,Array<DI>::class.java)
}
//class Deserializer:ResponseDeserializable<DI>{
// override fun deserialize(content: String) = Gson().fromJson(content,DI::class.java)
//}
}

Any idea ?

Thanks


#2

GSON is telling you it expected the first character of the stream to be [, but it was in fact ". Your example JSON doesn’t reflect that, but…GSON wouldn’t lie. So double-check that your JSON is exactly what you think it is. Set a breakpoint if you have to.