File tree Expand file tree Collapse file tree
codegen/src/main/java/com/squareup/moshi/kotlin/codegen
tests/src/test/kotlin/com/squareup/moshi/kotlin Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -390,8 +390,7 @@ private fun declaredProperties(
390390 propertySpec = property,
391391 parameter = parameter,
392392 visibility = property.modifiers.visibility(),
393- jsonName = parameter?.jsonName ? : property.annotations.jsonName()
394- ? : name.escapeDollarSigns(),
393+ jsonName = parameter?.jsonName ? : property.annotations.jsonName() ? : name,
395394 jsonIgnore = isIgnored
396395 )
397396 }
@@ -517,10 +516,6 @@ private fun <T> AnnotationSpec.elementValue(name: String): T? {
517516 }?.value?.value as ? T
518517}
519518
520- private fun String.escapeDollarSigns (): String {
521- return replace(" \$ " , " \$ {\' \$ \' }" )
522- }
523-
524519internal val TypeElement .metadata: Metadata
525520 get() {
526521 return getAnnotation(Metadata ::class .java)
Original file line number Diff line number Diff line change @@ -243,8 +243,7 @@ private fun declaredProperties(
243243 propertySpec = propertySpec,
244244 parameter = parameter,
245245 visibility = property.getVisibility().toKModifier() ? : KModifier .PUBLIC ,
246- jsonName = parameter?.jsonName ? : property.jsonName()
247- ? : name.escapeDollarSigns(),
246+ jsonName = parameter?.jsonName ? : property.jsonName() ? : name,
248247 jsonIgnore = isTransient || parameter?.jsonIgnore == true || property.jsonIgnore()
249248 )
250249 }
@@ -279,7 +278,3 @@ private fun KSPropertyDeclaration.toPropertySpec(
279278 }
280279 .build()
281280}
282-
283- private fun String.escapeDollarSigns (): String {
284- return replace(" \$ " , " \$ {\' \$ \' }" )
285- }
Original file line number Diff line number Diff line change @@ -743,6 +743,22 @@ class DualKotlinTest {
743743 this .b = b
744744 }
745745 }
746+
747+ @Test fun propertyNameHasDollarSign () {
748+ val moshi = Moshi .Builder ().add(KotlinJsonAdapterFactory ()).build()
749+ val jsonAdapter = moshi.adapter<PropertyWithDollarSign >()
750+
751+ val value = PropertyWithDollarSign (" apple" , " banana" )
752+ val json = """ {"${' $' } a":"apple","${' $' } b":"banana"}"""
753+ assertThat(jsonAdapter.toJson(value)).isEqualTo(json)
754+ assertThat(jsonAdapter.fromJson(json)).isEqualTo(value)
755+ }
756+
757+ @JsonClass(generateAdapter = true )
758+ data class PropertyWithDollarSign (
759+ val `$a`: String ,
760+ @Json(name = " \$ b" ) val b : String
761+ )
746762}
747763
748764typealias TypeAlias = Int
You can’t perform that action at this time.
0 commit comments