- Notifications
You must be signed in to change notification settings - Fork181
🚀 Plugin for Android Studio And IntelliJ Idea to generate Kotlin data class code from JSON text ( Json to Kotlin )
License
wuseal/JsonToKotlinClass
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Hi, Welcome! This is a plugin to generate Kotlindata class from JSON string, in another word, a plugin that converts JSON string to Kotlindata class (Json to Kotlin).We also have aJava/Kotlinlibrary. With this you can generate Kotlindata class from JSON stringprogrammatically.
implementation'com.sealwu.jsontokotlin:library:3.7.4'This is a very cool tool for Kotlin developers, it can convert a JSON string to Kotlindata class. The tool could not only recognize the primitive types but also auto create complex types. It's easily accessible, we provide shortcut keymapALT + K for Windows andOption + K for Mac, have a try and you'll fall in love with it! JsonToKotlinClass just makes programming more enjoyable, enjoy coding!
- Search 'JsonToKotlinClass' in Intellij Idea Plugin Repository Or AndroidStudio Plugin Repository And Install it.
File --> Settings --> Plugins --> Browse Repositories --> Search JsonToKotlinClass
Restart your IDE
Press
ALT + Kfor Windows orOption + Kfor Mac or right click on package ->New->Kotlin data clas file from JSONand continue as guided.
Have a try with the advanced dialog 😜
- Generating Kotlin data class from any legal JSON string/JSONSchema or anyURLs that returns a JSON string/JSONSchema as response orlocal file that contains JSON string/JSONSchema, for more detail about supported source types, refer tothe documentation
- Generating Kotlin data class from any legal JSON text when right click on directory and select
New->Kotlin data class File from JSON - Supporting (almostly) all kinds of JSON libs' annotation(Gson, Jackson, Fastjson, MoShi and LoganSquare, kotlinx.serialization(default custom value))
- Customizing your own annotations
- Initializing properties with default values
- Allowing properties to be nullable(?)
- Determining property nullability automatically
- Renaming property names to be camelCase style when selecting a target JSON lib annotation.
- Generating Kotlin
data classas individual classes - Generating Kotlin
data classas inner classes - Formatting any legal JSON string
- Generating Map Type when json key is primitive type
- Android Parcelable support
- Customize parent class declaration
- Generating kotlin data class property order by alphabetical
- Support customizing this plugin by
Extensionsmodule
This is the example JSON from json.org
{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML" ] },"GlossSee":"markup" } } } }}And with this plugin converting, Kotlin data classes would generate like this by default
data classExample(valglossary:Glossary)data classGlossary(valGlossDiv:GlossDiv,valtitle:String)data classGlossDiv(valGlossList:GlossList,valtitle:String)data classGlossList(valGlossEntry:GlossEntry)data classGlossEntry(valAbbrev:String,valAcronym:String,valGlossDef:GlossDef,valGlossSee:String,valGlossTerm:String,valID:String,valSortAs:String)data classGlossDef(valGlossSeeAlso:List<String>,valpara:String)
Want to try out the newest features?
$ git clone https://github.com/wuseal/JsonToKotlinClass$cd JsonToKotlinClass$ ./gradlew buildPluginAnd you're done! Go to directorybuild/distributions and you'll findJsonToKotlinClass-x.x.zip, which can be installed viaInstall plugin from disk....
Find it useful and want to contribute? All sorts of contributions are welcome, including but not limited to:
Open an issuehere if you find a bug;
Help test the EAP version and report bugs:
Go to the "Plugins" settings, click "Browse repositories..." => "Manage repositories..." and click the "+" button to add the EAP channel repository URL "https://plugins.jetbrains.com/plugins/eap/list". Optionally, you can also add the Alpha and Beta channel repository URLs "https://plugins.jetbrains.com/plugins/alpha/list" and "https://plugins.jetbrains.com/plugins/beta/list".
Kindly note that the "EAP" or "Alpha" or "Beta" channel update may be unstable and tend to be buggy, if you want to get back to the stable version, remove the "EAP" or "Alpha" or "Beta" version and reinstall this plugin from the "JetBrains Plugin Repository" channel, which can be filtered by the drop-down menu next to the search input field.
- Contribute your code:
$ git clone https://github.com/wuseal/JsonToKotlinClass$cd JsonToKotlinClassOpen thebuild.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 PRhere!
- Any kind of issues are welcome.
- Pull Requests are highly appreciated.
- Thank@davidbilik for giving me the first awesome advice.
- Thank@cgoodroe for opening many awesome issues for me, help me improve myself
- Thank@wangzhenguang for reminding me of the details of the problem
- Thank@kezhenxu94 for introducing CI/CD to save me a lot of time :)
- Thankiqbalhood for contributing logo for this project
- Thankakindone for adding
order by alphabeticalfeature forJsonToKotlinClass - Thankrafalbednarczuk for adding
make keyword property validfeature forJsonToKotlinClass
- Support and encourage me by clicking the ⭐ button on the upper right of this page. ✌️
- Share to others to help more people have a better develope expierience ❤️
This project exists thanks to all the people who contribute.
The development of this plugin is powerly driven by JetBrains.
| Let's talk |
|---|
| Join JsonToKotlinClass Slack |
| Join JsonToKotlinClass Telegram |
We analytics anonymous user behavior for improving plugin production, we've provided a switch case for that.
About
🚀 Plugin for Android Studio And IntelliJ Idea to generate Kotlin data class code from JSON text ( Json to Kotlin )
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.




