Skip to content

Commit 5804593

Browse files
committed
bugfix: fix #94
1 parent 1650628 commit 5804593

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/main/kotlin/wu/seal/jsontokotlin/KotlinCodeMaker.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ class KotlinCodeMaker {
113113
val classAnnotation = KClassAnnotation.getClassAnnotation(className.toString())
114114
stringBuilder.append(classAnnotation)
115115
if (classAnnotation.isNotBlank()) stringBuilder.append("\n")
116-
stringBuilder.append("data class ").append(className).append("(\n")
116+
if (inputElement?.isJsonNull == true || (inputElement as? JsonObject)?.entrySet()?.isEmpty() == true) {
117+
stringBuilder.append("class ").append(className).append("(\n")
118+
} else {
119+
stringBuilder.append("data class ").append(className).append("(\n")
120+
}
117121
}
118122

119123

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package wu.seal.jsontokotlin.regression
2+
3+
import com.winterbe.expekt.should
4+
import org.junit.Before
5+
import org.junit.Test
6+
import wu.seal.jsontokotlin.KotlinCodeMaker
7+
import wu.seal.jsontokotlin.test.TestConfig
8+
9+
/**
10+
* Created by kezhenxu at 2018/12/30 11:45
11+
*
12+
* @author kezhenxu (kezhenxu94 at 163 dot com)
13+
*/
14+
class Issue094Test {
15+
private val testJson = """
16+
{ "test": {} }
17+
""".trimIndent()
18+
private val expected = """
19+
data class A(
20+
@SerializedName("test") val test: Test = Test()
21+
) {
22+
23+
class Test(
24+
)
25+
}"""
26+
27+
@Before
28+
fun setUp() {
29+
TestConfig.setToTestInitState()
30+
}
31+
32+
@Test
33+
fun testIssue087() {
34+
KotlinCodeMaker("A", testJson).makeKotlinData().should.be.equal(expected)
35+
}
36+
}

0 commit comments

Comments
 (0)