Avatar ·

How to convert JSON to Data Class in Kotlin using GSON?

Hi everyone! I'm a beginner Kotlin developer transitioning from Java. I have a simple JSON that I receive from an API:\n\n```json\n{\n "userId": 1,\n "id": 1,\n "title": "delectus aut autem",\n "completed": false\n}\n```\n\nI want to parse it into a Data Class in Kotlin using the GSON library. Previously in Java, I did it like this:\n\n```java\npublic class Todo {\n private int userId;\n private int id;\n private String title;\n private boolean completed;\n // getters and setters...\n}\nGson gson = new Gson();\nTodo todo = gson.fromJson(jsonString, Todo.class);\n```\n\nNow in Kotlin I created a Data Class:\n\n```kotlin\ndata class Todo(\n val userId: Int,\n val id: Int,\n val title: String,\n val completed: Boolean\n)\n```\n\nBut when I try to parse:\n\n```kotlin\nval gso