Dawid Hyzy
02/11/2020, 6:44 AMvar abc2 = client2.newCall(post2).enqueue(object: Callback {
override fun onResponse(call: Call, response: Response) {
if(response.isSuccessful){
val resp = response.body?.string()
val gson = GsonBuilder().create()
val feed: List<Feed> = gson.fromJson(resp,Array<Feed>::class.java).toList()
}
override fun onFailure(call: Call, e: IOException) {
println("GAGAL")
}
})
class Feed(val feed: List<Penyimpangan>)
class Penyimpangan(val kodenik:String,val namakaryawan:String, val kodebagian:String, val tglupdate:String, val tglabsen:String,
val jamin:String, val jamout:String)
The problem is, when I try to see the value of feed, it throws something like this :
[com.example.penyimpangan_idm.ApprovalpenyimpanganActivity$Feed@4cef17c]
My output from resp is like this :
[{"kodenik":"2013129733","namakaryawan":"YASTI RIZKIA","kodebagian":"TRIE","tglupdate":"2019-12-09","tglabsen":"2019-12-09","jamin":"10:05","jamout":""}]
Amirul Zin
02/11/2020, 6:53 AMclass Penyimpangan( .. )
Doesn’t fully implement toString()
and relies on the default Java toString
implementation. Hence why you see that during logging.
You can easily see a detailed toString
by marking it as a data class
instead i.e. data class Penyimpangan()
since data class in Kotlin automatically creates a more detailed implementation of toString
for you.Dawid Hyzy
02/11/2020, 6:58 AMAmirul Zin
02/11/2020, 9:25 AMFeed
class and Penyimpangan
class must be both a data class. You simply need to add the data
keyword to the class definitiondata clas Feed( ... )
toString()
of the object instance, and you wanted it to log the class properties instead. Hence why you are only missing the data
class keyword : https://kotlinlang.org/docs/reference/data-classes.html.
If this is not the exact problem, can you clarify with what exactly you are trying to see/achieve here?Dawid Hyzy
02/12/2020, 1:56 AM