0
data class A (val x: Array<String>? = null) {
    val y = x?.filter { it!="something" }
}

This code should make member y to be calculated when an A object is created.

When I initiate an A object, both x and y gets a value. However, when I define object A as a response in a GET request using retrofit2, x gets a value but y is null. I cannot figure out the reason, (maybe relative to threads? I am using retrofit with coroutines), but can not explain it.

Any ideas?

geexee
  • 339
  • 2
  • 13

1 Answers1

0

This will depend on which Converter.Factory you use for Retrofit, but yours probably uses reflection in a way which doesn't actually call the constructor. I'd try MoshiConverterFactory (if your GET response is JSON) and see if it fixes the problem.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487