07-20-2023, 04:40 PM
I'm following [this example](
```
Type mismatch: inferred type is Data but SerializationStrategy<TypeVariable(T)> was expected
```
Here's my code:
```
import kotlinx.serialization.json.Json
import kotlinx.serialization.Serializable
@Serializable
data class Data(val a: Int, val str: String = "str")
fun main() {
println(Json.encodeToString(Data(42)))
}
```
Since I am using the @Serializable annotation, shouldn't I have the right data type? How can I serialize the data class?
[To see links please register here]
) to serialize a data class. When I do so, I get this build error:```
Type mismatch: inferred type is Data but SerializationStrategy<TypeVariable(T)> was expected
```
Here's my code:
```
import kotlinx.serialization.json.Json
import kotlinx.serialization.Serializable
@Serializable
data class Data(val a: Int, val str: String = "str")
fun main() {
println(Json.encodeToString(Data(42)))
}
```
Since I am using the @Serializable annotation, shouldn't I have the right data type? How can I serialize the data class?