JsonToKotlin插件(Kotlin开发神器)-Json数据生成Data Class,支持Gson,JackSon,FastJson

·  阅读 1961
原文链接: github.com

GitHub release GitHub stars GitHub issues GitHub closed issues GitHub contributors license

Kotlin IntelliJ Idea Plugin Android Studio Plugin

Hi,Welcome to come to see me! I am a plugin for Kotlin generate Kotlin data class code from a json string

I am a plugin for Kotlin to convert Json String into Kotlin data class code (Json to Kotlin)


Hi,This is a very cool tool for Kotlin developers ,It can convert the Json String into Kotlin Data Class code ,and paste it into your editor file ,The tool could recognize the Primitive Type of Json String and make Type Identifier respectively ,It taste easily ,Just have test,guys! Just press short key ALT + K ,And then,start your Kotlin program travel ! JsonToKotlin make program more happy!

Update Log


  • Fix an issue about Fastjson property name #Issue9
  • Fix an issue about using in none network condition it will be stuck #Issue10


  • Add supporter for Jackson annotation generate,supporter json lib --Jackson.
  • Add supporter for Fastjson annotation generate,supporter json lib --Fastjson.
  • Beautify the config settings dialog.


  • Add property init with default value option in property tab.(Recommend to select,with this selected you can avoid NullPointException in the following time,You can also unSelect the nullable option to avoid null check when use the data value).
  • Add property could be nullable option in property tab.
  • Fix a bug when the property name is 'list' and it's type is array then the plugin will broken.
  • Beautify dialog layout.


  • Fix insert improt class code upon package declare
  • Format property name and class name to camelcase name


  • Add support for generate anotations for target json lib --gson
  • Add Comment option to switch the comment content to append


  • Add property keyword config setting like ('var' or 'val'),the default keyword changed to 'val'.

How to use

  • Search 'JsonToKotlin' in Intellij Idea Plugin Repositroy Or AndroidStudio Plugin Repository And Install it.
  • Restart your Develop tools
  • Press short key ALT + K And Then you will know how to use


alt text

Configure with Jackson support on and init with deault value on and comment off

alt text

Config with Gson support on and init with deault value on

alt text

Generate Example

  • Example with none json lib support and comment option on

        data class FD(
                val programmers: List<Programmer>,
                val authors: List<Author>,
                val musicians: List<Musician>
        data class Musician(
                val firstName: String, //Eric
                val lastName: String, //Clapton
                val instrument: String //guitar
        data class Author(
                val firstName: String, //Isaac
                val lastName: String, //Asimov
                val genre: String //science fiction
        data class Programmer(
                val firstName: String, //Brett
                val lastName: String, //McLaughlin
                val email: String //aaaa
  • Example with gson option on and init with default value option on

       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, //12490639969101
       		@SerializedName("content") val content: List<Int> = listOf()
       data class TrainInfo(
       		@SerializedName("T110") val t110: T110 = T110()

Chinese Detail Document (中文文档)


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


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

Find me useful ? :heart:

  • Support me by clicking the :star: button on the upper right of this page. :v:
已添加到「」, 点击更改