how can I solve this ‘no args’ issue
# announcements
s
how can I solve this ‘no args’ issue
c
what are you parsing it with? GSON?
s
yes
c
You could try using InstanceCreator like GSON docs suggest, but GSON + Kotlin is not an ideal combination, I'd either use jackson with kotlin module registered or kotlin-specific lib, like klaxon or koshi
k
Why don't you make it enum class then?
c
Another problem here is
val type: MenuTypeModel
serializer will try to instantiate the parent instead of
MAP
,
CALENDAR
or
LEADERBOARD
which you probably want.
s
I am trying to avoid using enum in Android as it is recommended by many not to use enums
c
It is recommended not to use Enums only to save up on memory and CPU when you can do the same thing with a constant, by using sealed classes you are defeating the purpose of avoiding enums
s
oh.
I should go back to using stringDef then.
c
yeah, use of enum in this case is (probably) lighter than sealed classes 🙂 In the future always check why something is or isn't recommended.
👍 1
1
g
In general It’s completely fine to use Enums on Android. If Enum or Sealed class solves your problem just use it. At least it’s more type safe than StringDef
👍 1
In your case I don’t see any reason to use Sealed class instead of Enum.