File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
main/kotlin/wu/seal/jsontokotlin
test/kotlin/wu/seal/jsontokotlin/regression Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments