mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Improve the way Json.name is fetched for codegen (#1059)
* Improve the way Json.name is fetched for codegen * Remove the comment for jsonName * Add a test for json names with quotation marks * Fix the broken tests
This commit is contained in:
committed by
Zac Sweers
parent
365e955381
commit
cc4b5b3ad2
@@ -87,6 +87,26 @@ class GeneratedAdaptersTest {
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class JsonAnnotationWithDollarSign(@Json(name = "\$foo") val bar: String)
|
||||
|
||||
@Test
|
||||
fun jsonAnnotationWithQuotationMark() {
|
||||
val adapter = moshi.adapter<JsonAnnotationWithQuotationMark>()
|
||||
|
||||
// Read
|
||||
val json = """{"\"foo\"": "bar"}"""
|
||||
|
||||
val instance = adapter.fromJson(json)!!
|
||||
assertThat(instance.bar).isEqualTo("bar")
|
||||
|
||||
// Write
|
||||
val expectedJson = """{"\"foo\"":"baz"}"""
|
||||
|
||||
assertThat(adapter.toJson(
|
||||
JsonAnnotationWithQuotationMark("baz"))).isEqualTo(expectedJson)
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class JsonAnnotationWithQuotationMark(@Json(name = "\"foo\"") val bar: String)
|
||||
|
||||
@Test
|
||||
fun defaultValues() {
|
||||
val adapter = moshi.adapter<DefaultValues>()
|
||||
|
Reference in New Issue
Block a user