-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from nanjingboy/fix/generate
[Fix] Kotlin Data Class don't generated as expected
- Loading branch information
Showing
4 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,7 @@ | |
!.gitignore | ||
!.travis.yml | ||
|
||
local.properties | ||
|
||
build/ | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/kotlin/wu/seal/jsontokotlin/regression/Issue121Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package wu.seal.jsontokotlin.regression | ||
|
||
import com.winterbe.expekt.should | ||
import org.junit.Before | ||
import org.junit.Test | ||
import wu.seal.jsontokotlin.KotlinDataClassCodeMaker | ||
import wu.seal.jsontokotlin.test.TestConfig | ||
|
||
class Issue121Test { | ||
|
||
private val json = """{"data": [ | ||
[ | ||
{ | ||
"id": 1, | ||
"question": "This is test question?", | ||
"answer": "Ok i understand.", | ||
"created": "2019-03-28T15:37:06+05:30", | ||
"created_by": 0, | ||
"modified": "2019-03-28T15:37:06+05:30", | ||
"modified_by": 0, | ||
"active": 1, | ||
"is_del": 0 | ||
}, | ||
{ | ||
"id": 2, | ||
"question": "What is soulmate?", | ||
"answer": "answer", | ||
"created": "2019-03-28T15:41:52+05:30", | ||
"created_by": 0, | ||
"modified": "2019-03-28T15:41:52+05:30", | ||
"modified_by": 0, | ||
"active": 1, | ||
"is_del": 0 | ||
} | ||
] | ||
] | ||
}""" | ||
|
||
private val expected = """data class Test( | ||
@SerializedName("data") | ||
val `data`: List<List<Data>> = listOf() | ||
) { | ||
data class Data( | ||
@SerializedName("active") | ||
val active: Int = 0, // 1 | ||
@SerializedName("answer") | ||
val answer: String = "", // answer | ||
@SerializedName("created") | ||
val created: String = "", // 2019-03-28T15:41:52+05:30 | ||
@SerializedName("created_by") | ||
val createdBy: Int = 0, // 0 | ||
@SerializedName("id") | ||
val id: Int = 0, // 2 | ||
@SerializedName("is_del") | ||
val isDel: Int = 0, // 0 | ||
@SerializedName("modified") | ||
val modified: String = "", // 2019-03-28T15:41:52+05:30 | ||
@SerializedName("modified_by") | ||
val modifiedBy: Int = 0, // 0 | ||
@SerializedName("question") | ||
val question: String = "" // What is soulmate? | ||
) | ||
}""" | ||
|
||
/** | ||
* init test environment before test | ||
*/ | ||
@Before | ||
fun setUp() { | ||
TestConfig.setToTestInitState() | ||
} | ||
|
||
/** | ||
* test issue #121 of Github Project issue | ||
*/ | ||
@Test | ||
fun testIssue089() { | ||
val result = KotlinDataClassCodeMaker("Test", json).makeKotlinDataClassCode() | ||
result.trim().should.be.equal(expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters