JSON To Kotlin

Additional

Language
Kotlin
Version
V2.0 (Apr 26, 2018)
Created
Aug 29, 2017
Updated
May 18, 2018
Owner
Seal (wuseal)
Contributors
mladenrakonjac
Seal (wuseal)
sealkingking
kezhenxu94
4
Activity
Badge
Generate
Download
Source code

Commercial

JsonToKotlinClass

Hi,Welcome to come to see me! I am a plugin for Kotlin generate Kotlin data class code from a JSON string also as say a plugin for Kotlin to convert JSON String into Kotlin data class code (Json to Kotlin)

Overview

Hi,This is a very cool tool for Kotlin developers ,It can convert the Json String into Kotlin Data Class code ,The tool could recognize the Primitive Type of Json String and make Type Identifier respectively ,It taste easily ,Just have test,guys! Just press shortcut key ALT + K for Windows or Option + K for Mac,And then,start your Kotlin programming travel ! JsonToKotlinClass make programming more happy!

Easy Use

Want to generate classes code in inner class model? Do like this.

Want to generate Kotlin data class file directory? Do like this.

Want to generate Kotlin data classes in single file directory? Do like this.

Usage

  • Search 'JsonToKotlinClass' in Intellij Idea Plugin Repositroy Or AndroidStudio Plugin Repository And Install it.
    File --> Settings --> Plugins --> Browse Repositories -->Search JsonToKotlinClass
  • Restart your Develop tools
  • Press shortcut key ALT + K for Windows or Option + K for Mac Or right click on package -> New-> Kotlin data clas file from JSON  And Then you will know how to use

Advanced usage

Have a try with the settings 😜

Features

  • Generate Kotlin data class from any legal JSON text.
  • Generate Kotlin data class File form any legal JSON text when right click on directory and select New -> Kotlin data class File from JSON.
  • Support JSON Serialize Lib Annotation(Gson,Jackson,Fastjson,MoShi and LoganSquare,kotlinx.serialization(default custom value))
  • Support customize your own Annotation
  • Support init property with default value
  • Support make property type to be nullable(?)
  • Support auto make sure property type to be nullable(?) or not
  • Support auto rename property name to be camelCase when select a target JSON lib Annotation.
  • Support generate kotlin data class code in split model
  • Support generate kotlin data class code in inner class model
  • Support generate kotlin data class File in inner class model
  • Support generate kotlin data class File in split files
  • Support format any legal JSON string
  • Support Generate Map Type when json key is primitive type

Generate Example

  • Default

        data class FD(
            val programmers: List<Programmer>,
            val authors: List<Author>,
            val musicians: List<Musician>
        )
        
        data class Musician(
            val firstName: String, 
            val lastName: String, 
            val instrument: String 
        )
        
        data class Author(
            val firstName: String, 
            val lastName: String, 
            val genre: String 
        )
        
        data class Programmer(
            val firstName: String, 
            val lastName: String, 
            val email: String 
        )
    
  • Example with gson option on and init with default value option on in settings

       data class TestData(
           @SerializedName("ticketInfo") val ticketInfo: TicketInfo = TicketInfo(),
           @SerializedName("trainInfo") val trainInfo: TrainInfo = TrainInfo(),
           @SerializedName("trainScheduleHead") val trainScheduleHead: List<String> = listOf(),
           @SerializedName("extInfo") val extInfo: ExtInfo = ExtInfo(),
           @SerializedName("trainScheduleBody") val trainScheduleBody: List<TrainScheduleBody> = listOf()
       )
       
       data class TrainScheduleBody(
           @SerializedName("mxl") val mxl: Long = 0, 
           @SerializedName("content") val content: List<Int> = listOf()
       )
       
       data class TrainInfo(
           @SerializedName("T110") val t110: T110 = T110()
       )
     
    

Build From Source

Want to try out the newest features?

$ git clone https://github.com/wuseal/JsonToKotlinClass
$ cd JsonToKotlinClass
$ ./gradlew buildPlugin

And you're done! Go to directory build/distributions and you'll find JsonToKotlinClass-x.x.zip.

Contribute to This Repo

Find it useful and want to contribute?

$ git clone https://github.com/wuseal/JsonToKotlinClass
$ cd JsonToKotlinClass

Open the build.gradle in IntelliJ, open "Gradle" tool window, expand the project view to "JsonToKotlinClass | Tasks | intellij | runIde", right-click and choose "Debug ...", and you're done! Create your PR here!

Chinese Detail Document (中文文档)

Others

  • Welcome anyone to raise new issue.
  • Welcome anyone to push a pull request to improve me.

Thanks

  • Thank @davidbilik give me first awesome advice.
  • Thank @cgoodroe raise many awesome issues for me,Help me improve myself
  • Thank @wangzhenguang remains me the details of problem

Find me useful ? ❤️

  • Support me by clicking the ⭐️ button on the upper right of this page. ✌️
  • Spread to others to let more people have a better develope expierience ❤️