Skip to content

Commit 955dec4

Browse files
author
seal
committed
Release Version 1.4.1
Fix two issues
1 parent b105924 commit 955dec4

File tree

8 files changed

+61
-5
lines changed

8 files changed

+61
-5
lines changed

JsonToKotlin.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<exclude-output />
66
<content url="file://$MODULE_DIR$">
77
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
89
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
910
</content>
1011
<orderEntry type="inheritedJdk" />

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ I am a plugin for Kotlin to convert Json String into Kotlin data class code (Jso
2020
### Overview
2121
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!
2222
### Update Log
23+
#### 1.4.1
24+
* Fix an issue about Fastjson property name [#Issue9](https://github.com/wuseal/JsonToKotlinClass/issues/9)
25+
* Fix an issue about using in none network condition it will be stuck [#Issue10](https://github.com/wuseal/JsonToKotlinClass/issues/10)
2326
#### 1.4
2427
* Add supporter for Jackson annotation generate,supporter json lib --Jackson.
2528
* Add supporter for Fastjson annotation generate,supporter json lib --Fastjson.

resources/META-INF/plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>wu.seal.tool.jsontokotlin</id>
33
<name>JsonToKotlinClass</name>
4-
<version>1.4</version>
4+
<version>1.4.1</version>
55
<vendor email="[email protected]" url="https://www.github.com/wuseal">Seal</vendor>
66

77
<description><![CDATA[
@@ -11,6 +11,9 @@
1111
]]></description>
1212

1313
<change-notes><![CDATA[
14+
1.4.1:<br>
15+
* Fix an issue about Fastjson property name [#ISSUE9](https://github.com/wuseal/JsonToKotlinClass/issues/9)<br>
16+
* Fix an issue about using in none network condition it will be stuck [#ISSUE10](https://github.com/wuseal/JsonToKotlinClass/issues/10)<br>
1417
1.4:<br>
1518
* Add supporter for Jackson annotation generate,supporter json lib --Jackson.<br>
1619
* Add supporter for Fastjson annotation generate,supporter json lib --Fastjson.<br>

src/wu/seal/jsontokotlin/FastjsonSupporter.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object FastjsonSupporter:IJsonLibSupporter {
2525

2626
fastjsonSupportPropertyBuilder.append(" ")
2727

28-
fastjsonSupportPropertyBuilder.append(KPropertyName.getName(rawPropertyName))
28+
fastjsonSupportPropertyBuilder.append(KPropertyName.getName(removeStartIsCharactors(rawPropertyName)))
2929

3030
fastjsonSupportPropertyBuilder.append(": ")
3131

@@ -40,5 +40,16 @@ object FastjsonSupporter:IJsonLibSupporter {
4040
return fastjsonSupportPropertyBuilder.toString()
4141
}
4242

43+
private fun removeStartIsCharactors(rawPropertyName: String): String {
44+
if (rawPropertyName.startsWith("is")) {
4345

46+
var modifyPropertyName = rawPropertyName.removePrefix("is")
47+
while (modifyPropertyName.startsWith("is")) {
48+
modifyPropertyName = modifyPropertyName.removePrefix("is")
49+
}
50+
return modifyPropertyName
51+
} else {
52+
return rawPropertyName
53+
}
54+
}
4455
}

src/wu/seal/jsontokotlin/JsonToKotlinApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import wu.seal.jsontokotlin.statistics.sendHistoryActionInfo
1010
* Created by Seal.wu on 2017/8/21.
1111
*/
1212

13-
const val PLUGIN_VERSION = "1.4"
13+
const val PLUGIN_VERSION = "1.4.1"
1414

1515
class JsonToKotlinApplication : ApplicationComponent {
1616

src/wu/seal/jsontokotlin/KotlinMaker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class KotlinMaker {
9696
fun main(args: Array<String>) {
9797
isTestModel = true
9898
val json1 = """{ "progr ammers": [
99-
{ "FirstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
99+
{ "isFirstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
100100
{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },
101101
{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
102102
],

src/wu/seal/jsontokotlin/MakeKotlinClassAction.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ class MakeKotlinClassAction : AnAction("MakeKotlinClass") {
7575
}
7676

7777
Messages.showMessageDialog(project, "Kotlin Code insert successfully!", "Information", Messages.getInformationIcon())
78-
sendActionInfo(gson.toJson(SuccessCompleteAction()))
78+
Thread {
79+
sendActionInfo(gson.toJson(SuccessCompleteAction()))
80+
}.start()
7981
} catch(e: Exception) {
8082
getUncaughtExceptionHandler(jsonString) {
8183
Messages.showErrorDialog("I am sorry,JsonToKotlin may occur a RuntimeException,You could try again later or recover to the old version", "Occur a fatal error")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package wu.seal.jsontokotlin
2+
3+
import org.junit.*
4+
5+
import org.junit.Assert.*
6+
7+
/**
8+
* Created by Seal.Wu on 2017/10/19.
9+
*/
10+
class FastjsonSupporterTest {
11+
@org.junit.Test
12+
fun getJsonLibSupportPropertyBlockString() {
13+
14+
isTestModel = true
15+
16+
val propertyStringBlock1 = FastjsonSupporter.getJsonLibSupportPropertyBlockString("ABC", "String")
17+
val propertyStringBlock2 = FastjsonSupporter.getJsonLibSupportPropertyBlockString("isABC", "String")
18+
val propertyStringBlock3 = FastjsonSupporter.getJsonLibSupportPropertyBlockString("isisisABC", "String")
19+
val propertyStringBlock4 = FastjsonSupporter.getJsonLibSupportPropertyBlockString("ISABC", "String")
20+
val propertyStringBlock5 = FastjsonSupporter.getJsonLibSupportPropertyBlockString("isISABC", "String")
21+
22+
println(propertyStringBlock1)
23+
println(propertyStringBlock2)
24+
println(propertyStringBlock3)
25+
println(propertyStringBlock4)
26+
println(propertyStringBlock5)
27+
28+
assertFalse(propertyStringBlock1.startsWith("is"))
29+
assertFalse(propertyStringBlock2.startsWith("is"))
30+
assertFalse(propertyStringBlock3.startsWith("is"))
31+
assertFalse(propertyStringBlock4.startsWith("is"))
32+
assertFalse(propertyStringBlock5.startsWith("is"))
33+
34+
}
35+
36+
}

0 commit comments

Comments
 (0)