Skip to content

Commit 02bb855

Browse files
authored
Merge pull request #106 from kezhenxu94/bugfix-doc
add doc and fix bug
2 parents 8dbd663 + 4c6a233 commit 02bb855

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This is a very cool tool for Kotlin developers, it can convert a JSON string to
4444
Have a try with the settings dialog :stuck_out_tongue_winking_eye:
4545

4646
### Features
47-
* Generating Kotlin data class from any legal JSON string or any **URLs that returns a JSON string as response**
47+
* Generating Kotlin data class from any legal JSON string or any **URLs that returns a JSON string as response** or **local file that contains JSON string**, for more detail about supported source types, refer to [the documentation](https://github.com/wuseal/JsonToKotlinClass/blob/3.0/doc_for_json_sources.md)
4848
* Generating Kotlin data class from any legal JSON text when right click on directory and select `New` -> `Kotlin data class File from JSON`
4949
* Supporting (almostly) all kinds of JSON libs' annotation(Gson, Jackson, Fastjson, MoShi and LoganSquare, kotlinx.serialization(default custom value))
5050
* [Customizing your own annotations](https://github.com/wuseal/JsonToKotlinClass/issues/19)

doc_for_json_sources.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Here we currently support 3 types of JSON sources: `clipboard/input manually`, `Http Url` and `local file`, each of them are used as follows:
2+
3+
- clipboard/input manually
4+
5+
With this source type, you can edit the JSON string directly in the text area in the dialog,
6+
7+
[![type_directly](https://user-images.githubusercontent.com/15965696/51297231-72fbe380-1a5a-11e9-8d28-1294ecc3d221.gif)]
8+
9+
or paste JSON string from clipboard using shortcut `Ctrl+V` or `Command+V`.
10+
11+
- Http Url
12+
13+
With this source type, you can retrieve JSON string from a http GET request, to do this, right click on the text area and choose "Retrieve content from Http URL",
14+
15+
[![http](https://user-images.githubusercontent.com/15965696/51297482-6af07380-1a5b-11e9-8f3d-8b398dd82f34.gif)]
16+
17+
- Local File
18+
19+
With this source type, you can load a JSON string from a local file, to do this, right click on the text area and choose "Load from local file",
20+
21+
![local_file](https://user-images.githubusercontent.com/15965696/51298233-c5d79a00-1a5e-11e9-9a99-a65f09d90efc.gif)
22+
23+
If you want more types of source, please open an issue [here](https://github.com/wuseal/JsonToKotlinClass/issues) or implement yourself and create a pull request [here](https://github.com/wuseal/JsonToKotlinClass/pulls).

src/main/kotlin/wu/seal/jsontokotlin/ui/JsonInputDialog.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package wu.seal.jsontokotlin.ui
22

33
import com.google.gson.*
44
import com.intellij.json.JsonFileType
5+
import com.intellij.openapi.application.Application
6+
import com.intellij.openapi.application.ApplicationManager
57
import com.intellij.openapi.editor.Editor
68
import com.intellij.openapi.editor.EditorFactory
79
import com.intellij.openapi.fileChooser.FileChooser
@@ -194,7 +196,9 @@ class JsonInputDialog(classsName: String, private val project: Project) : Messag
194196
addActionListener {
195197
FileChooser.chooseFile(FileChooserDescriptor(true, false, false, false, false, false), null, null) { file ->
196198
val content = String(file.contentsToByteArray())
197-
jsonContentEditor.document.setText(content)
199+
ApplicationManager.getApplication().runWriteAction {
200+
jsonContentEditor.document.setText(content.replace("\r\n", "\n"))
201+
}
198202
}
199203
}
200204
}

0 commit comments

Comments
 (0)