``` "data": [ { "player_id": 2497, ...
# android
h
Copy code
"data": [
    {
      "player_id": 2497,
      "firstname": "Jay-Alistaire Frederick",
      "lastname": "Simpson",
      "birthday": "1988-12-01",
      "age": 32,
      "weight": 85,
      "height": 180,
    },
    {
      "player_id": 2570,
      "firstname": "Simranjit",
      "lastname": "Singh Thandi",
      "birthday": "1999-10-11",
      "age": 21,
      "weight": null,
      "height": null,
    }]
Hi i want to replace value of "weight" to 0 if its null from backend. How to do it in Data Class ? Any solution
o
if (player.weight == null) player.copy(weight = 0)
h
can you share proper example?
n
It seems that it is a JSON string and while deserializing you want to give one of the keys a default value. There are plenty of ways to do that. But you have to provide more context. Like which serializer you are using... like Gson, Moshi or Kotlin's own searialization library...
h
I'm using Gson
n
@haris mehmood Well, then you may look into Gson documentation. There would surely be a way. Or somebody might help here. I use Kotlin's serializer so I have no idea how to do that. Hopefully, there would be a simple annotation to add this behaviour in your model.