Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json to kotlin data classes [closed]

Is there existing service for generating kotlin data classes from json model in the way how it works on http://www.jsonschema2pojo.org/ site? My new project has over complicated API responses, so it would save me time.

like image 819
Gorets Avatar asked Nov 02 '16 23:11

Gorets


People also ask

How parse data from JSON to Kotlin?

We're going to parse JSON without using any 3rd party library but using the java class JSONTokener. With the JSONTokener, we can parse a JSON string into an object. These objects can be cast as JSONObject or as JSONArray.

Is data class open Kotlin?

Kotlin Data Class Requirements The parameters of the primary constructor must be marked as either val (read-only) or var (read-write). The class cannot be open, abstract, inner or sealed. The class may extend other classes or implement interfaces.

What is pojo in Kotlin?

Kotlin has been developed over JVM and hence it is fully compatible with JVM. Java POJO class stands for Plain Old Java Object (POJO) which is used to hold the data. In Java, along with defining the variables, we need to create different supporting methods in order to access those private members of the class.


1 Answers

There is a plugin for Android Studio and Intellij Idea called JsonToKotlinClass.

You can convert json into kotlin's data class with it: https://github.com/wuseal/JsonToKotlinClass

A AndroidStudio plugin for Converting json string into kotlin data class

like image 195
吴海豹 Avatar answered Oct 23 '22 15:10

吴海豹