Don't mangle property names that contain a dollar sign (#1446)

Without this fix the new test fails like this:

    value of: toJson(...)
    expected: {"$a":"apple","$b":"banana"}
    but was : {"${'$'}a":"apple","$b":"banana"}
This commit is contained in:
Jesse Wilson
2021-12-05 21:07:27 -05:00
committed by GitHub
parent fb5dd08168
commit bc441ad7f3
3 changed files with 18 additions and 12 deletions

View File

@@ -390,8 +390,7 @@ private fun declaredProperties(
propertySpec = property,
parameter = parameter,
visibility = property.modifiers.visibility(),
jsonName = parameter?.jsonName ?: property.annotations.jsonName()
?: name.escapeDollarSigns(),
jsonName = parameter?.jsonName ?: property.annotations.jsonName() ?: name,
jsonIgnore = isIgnored
)
}
@@ -517,10 +516,6 @@ private fun <T> AnnotationSpec.elementValue(name: String): T? {
}?.value?.value as? T
}
private fun String.escapeDollarSigns(): String {
return replace("\$", "\${\'\$\'}")
}
internal val TypeElement.metadata: Metadata
get() {
return getAnnotation(Metadata::class.java)

View File

@@ -243,8 +243,7 @@ private fun declaredProperties(
propertySpec = propertySpec,
parameter = parameter,
visibility = property.getVisibility().toKModifier() ?: KModifier.PUBLIC,
jsonName = parameter?.jsonName ?: property.jsonName()
?: name.escapeDollarSigns(),
jsonName = parameter?.jsonName ?: property.jsonName() ?: name,
jsonIgnore = isTransient || parameter?.jsonIgnore == true || property.jsonIgnore()
)
}
@@ -279,7 +278,3 @@ private fun KSPropertyDeclaration.toPropertySpec(
}
.build()
}
private fun String.escapeDollarSigns(): String {
return replace("\$", "\${\'\$\'}")
}