and when do i need a library to parse/make json?
# javascript
l
and when do i need a library to parse/make json?
s
unsafeCast
does nothing but tricks type system into thinking that value is of different type without checking it at runtime. It should be used with great care. We don't recommend casting 'bare' objects to Kotlin classes. While it might accidentally work in your case, class instances are more than just object, they include type metadata vital for type operators like
as
or
is
.
data
classes on top of that provide helper methods like
copy
,
toString
,
hashCode
,
equals
and these would be abcent from
unsafeCast
-ed bare object. Also, internal implementation of K/JS classes might change in the future releases and regular property access could break too. In your case it would be more appropriate to either: • Describe your objects using `external interface`s. • Use library to parse JSON There are, however, rare cases where
unsafeCast
could be useful. In performance-critical parts of the code, one might want to replace a regular
as
cast with
unsafeCast
if they know that it will always succed.
l
Cool! I understand! It sound just like C++ casting that can accidentally work too. Thank you for your answer.
Now I have to decide on a JSON parsing lib.. Ugh