mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Don't linebreak keys with spaces (#1053)
* Don't linebreak keys with spaces Resolves #1052 * Update kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt
This commit is contained in:
@@ -121,10 +121,17 @@ internal class AdapterGenerator(
|
|||||||
private val optionsProperty = PropertySpec.builder(
|
private val optionsProperty = PropertySpec.builder(
|
||||||
nameAllocator.newName("options"), JsonReader.Options::class.asTypeName(),
|
nameAllocator.newName("options"), JsonReader.Options::class.asTypeName(),
|
||||||
KModifier.PRIVATE)
|
KModifier.PRIVATE)
|
||||||
.initializer("%T.of(${nonTransientProperties.joinToString(", ") {
|
.initializer(
|
||||||
// We manually put in quotes because we know the jsonName is already escaped
|
"%T.of(%L)",
|
||||||
CodeBlock.of("\"%L\"", it.jsonName).toString()
|
JsonReader.Options::class.asTypeName(),
|
||||||
}})", JsonReader.Options::class.asTypeName())
|
nonTransientProperties
|
||||||
|
.map {
|
||||||
|
// We manually put in quotes because we know the jsonName is already escaped.
|
||||||
|
val whitespaceSafeName = it.jsonName.replace(" ", "·")
|
||||||
|
CodeBlock.of("\"$whitespaceSafeName\"")
|
||||||
|
}
|
||||||
|
.joinToCode(", ")
|
||||||
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
private val constructorProperty = PropertySpec.builder(
|
private val constructorProperty = PropertySpec.builder(
|
||||||
|
@@ -1216,6 +1216,18 @@ internal data class MismatchParentAndNestedClassVisibility(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for https://github.com/square/moshi/issues/1052
|
||||||
|
// Compile-only test
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class KeysWithSpaces(
|
||||||
|
@Json(name = "1. Information") val information: String,
|
||||||
|
@Json(name = "2. Symbol") val symbol: String,
|
||||||
|
@Json(name = "3. Last Refreshed") val lastRefreshed: String,
|
||||||
|
@Json(name = "4. Interval") val interval: String,
|
||||||
|
@Json(name = "5. Output Size") val size: String,
|
||||||
|
@Json(name = "6. Time Zone") val timeZone: String
|
||||||
|
)
|
||||||
|
|
||||||
// Has to be outside to avoid Types seeing an owning class
|
// Has to be outside to avoid Types seeing an owning class
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class NullableTypeParams<T>(
|
data class NullableTypeParams<T>(
|
||||||
|
Reference in New Issue
Block a user