-
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.
- Loading branch information
Showing
3 changed files
with
92 additions
and
18 deletions.
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
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
61 changes: 61 additions & 0 deletions
61
src/test/kotlin/wu/seal/jsontokotlin/regression/Issue391Test.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,61 @@ | ||
package wu.seal.jsontokotlin.regression | ||
|
||
import com.winterbe.expekt.should | ||
import org.junit.Test | ||
import wu.seal.jsontokotlin.generateKotlinClassCode | ||
import wu.seal.jsontokotlin.model.DefaultValueStrategy | ||
import wu.seal.jsontokotlin.model.PropertyTypeStrategy | ||
import wu.seal.jsontokotlin.model.TargetJsonConverter | ||
import wu.seal.jsontokotlin.test.TestConfig | ||
import wu.seal.jsontokotlin.utils.BaseTest | ||
|
||
class Issue391Test :BaseTest(){ | ||
|
||
|
||
@Test | ||
fun testIssue391() { | ||
val json = """ | ||
[ | ||
{ | ||
"url": null, | ||
"label": "« Previous", | ||
"active": false | ||
}, | ||
{ | ||
"url": "http://localhost:8000/api/active-announcements?page=1", | ||
"label": "1", | ||
"active": true | ||
}, | ||
{ | ||
"url": "http://localhost:8000/api/active-announcements?page=2", | ||
"label": "2", | ||
"active": false | ||
}, | ||
{ | ||
"url": "http://localhost:8000/api/active-announcements?page=3", | ||
"label": "3", | ||
"active": false | ||
}, | ||
] | ||
""".trimIndent() | ||
val expected = """ | ||
class Test : ArrayList<TestItem>() | ||
@JsonClass(generateAdapter = true) | ||
data class TestItem( | ||
@Json(name = "active") | ||
val active: Boolean = false, | ||
@Json(name = "label") | ||
val label: String = "", | ||
@Json(name = "url") | ||
val url: String? = null | ||
) | ||
""".trimIndent() | ||
TestConfig.targetJsonConvertLib = TargetJsonConverter.MoshiCodeGen | ||
TestConfig.isCommentOff = true | ||
TestConfig.isNestedClassModel = false | ||
TestConfig.defaultValueStrategy = DefaultValueStrategy.AllowNull | ||
TestConfig.propertyTypeStrategy = PropertyTypeStrategy.AutoDeterMineNullableOrNot | ||
json.generateKotlinClassCode("Test").should.equal(expected) | ||
} | ||
} |