arekolek
10/16/2018, 9:27 AMfromJson
function behaves with a generic type and found this. Can anybody explain why that instance check is sometimes true and other times false? š¤gildor
10/16/2018, 9:35 AMgildor
10/16/2018, 9:36 AMhho
10/16/2018, 9:38 AM.first().first()
on a List<List<Int>>
should result in an Int
, shouldn't it?gildor
10/16/2018, 9:38 AMarekolek
10/16/2018, 9:38 AMarekolek
10/16/2018, 9:38 AMarekolek
10/16/2018, 9:39 AMfirst().first()
itās thisgildor
10/16/2018, 9:40 AMgildor
10/16/2018, 9:41 AMgildor
10/16/2018, 9:41 AMgildor
10/16/2018, 9:42 AM::class
arekolek
10/16/2018, 9:43 AMgildor
10/16/2018, 9:45 AM::class
of first().first()?Nikky
10/16/2018, 9:47 AMarekolek
10/16/2018, 9:47 AMNikky
10/16/2018, 9:48 AMgildor
10/16/2018, 9:48 AMNikky
10/16/2018, 9:49 AMarekolek
10/16/2018, 9:49 AMgildor
10/16/2018, 9:49 AMgildor
10/16/2018, 9:50 AMNikky
10/16/2018, 9:50 AMgildor
10/16/2018, 9:50 AMNikky
10/16/2018, 9:50 AMgildor
10/16/2018, 9:51 AMarekolek
10/16/2018, 9:51 AMgildor
10/16/2018, 9:51 AMgildor
10/16/2018, 9:52 AM.javaClass
instead, without kotlin-reflect ::class can be used only for compile time known typesarekolek
10/16/2018, 9:53 AMarekolek
10/16/2018, 9:54 AMarekolek
10/16/2018, 9:54 AMNikky
10/16/2018, 9:55 AMgildor
10/16/2018, 9:55 AMfirst().first().javaClass
arekolek
10/16/2018, 9:56 AMarekolek
10/16/2018, 9:58 AMwhich lib is that fromJson() call from anyways ?@Nikky itās something my colleague came up with and I was wondering if itās something that actually works in all cases
Nikky
10/16/2018, 10:00 AMNikky
10/16/2018, 10:01 AMgildor
10/16/2018, 10:01 AMiād rather have the json deserialization fail and then be handed safe intsDeserialization shouldnāt fail in this case, itās completely valid case. What Json mapper should do in this case is actually parse value as Int instead of default āuniversalā double
bartvh
10/16/2018, 10:01 AMfromJson
is probably using unchecked generic operations to trick the compiler into thinking that something is an Int
, that is actually a double
at runtimegildor
10/16/2018, 10:02 AMNikky
10/16/2018, 10:02 AM,
was .
arekolek
10/16/2018, 10:03 AMwell... now i am curious.. is the lib on github ?Itās just a function internal to the project, the actual parsing is done by Gson
gildor
10/16/2018, 10:04 AMNikky
10/16/2018, 10:04 AMNikky
10/16/2018, 10:06 AMgildor
10/16/2018, 10:16 AMkingsley
10/16/2018, 2:31 PMfromJson
function looks like.
Like Bart said, if youāre implementing this based on erased types at runtime, then that might be the issue.arekolek
10/16/2018, 2:32 PMgildor
10/16/2018, 2:32 PMarekolek
10/16/2018, 2:33 PMarekolek
10/16/2018, 2:34 PMkingsley
10/16/2018, 2:47 PMobject : TypeToken<T>() {}.type
notation.
I was only able to make it work using explicitly:
TypeToken.getParameterized(List::class.java, TypeToken.getParameterized(List::class.java, Int::class.javaObjectType).type).type)
which is just too sad and uglyarekolek
10/16/2018, 4:51 PM