Skip to content

Commit

Permalink
Revert "Omit adapter field names now that we directly instantiate ann…
Browse files Browse the repository at this point in the history
…otations (#1436)" (#1439)

This reverts commit 4a6cfb4.
  • Loading branch information
ZacSweers committed Dec 1, 2021
1 parent fb8c7b5 commit 9f81ac8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Expand Up @@ -270,7 +270,8 @@ public class AdapterGenerator(
uniqueAdapter.delegateKey.generateProperty(
nameAllocator,
typeRenderer,
moshiParam
moshiParam,
uniqueAdapter.name
)
)
}
Expand Down
Expand Up @@ -45,7 +45,8 @@ public data class DelegateKey(
internal fun generateProperty(
nameAllocator: NameAllocator,
typeRenderer: TypeRenderer,
moshiParameter: ParameterSpec
moshiParameter: ParameterSpec,
propertyName: String
): PropertySpec {
val qualifierNames = jsonQualifiers.joinToString("") {
"At${it.typeName.rawType().simpleName}"
Expand All @@ -67,10 +68,10 @@ public data class DelegateKey(
", setOf(%L)" to arrayOf(jsonQualifiers.map { it.asInstantiationExpression() }.joinToCode())
}
}
val finalArgs = arrayOf(*standardArgs, *args)
val finalArgs = arrayOf(*standardArgs, *args, propertyName)

return PropertySpec.builder(adapterName, adapterTypeName, KModifier.PRIVATE)
.initializer("%N.adapter(%L$initializerString)", *finalArgs)
.initializer("%N.adapter(%L$initializerString, %S)", *finalArgs)
.build()
}
}
Expand Down
3 changes: 0 additions & 3 deletions moshi/src/main/java/com/squareup/moshi/Moshi.java
Expand Up @@ -109,10 +109,7 @@ public <T> JsonAdapter<T> adapter(Type type, Set<? extends Annotation> annotatio
/**
* @param fieldName An optional field name associated with this type. The field name is used as a
* hint for better adapter lookup error messages for nested structures.
* @deprecated this is no longer needed in Kotlin 1.6.0 (which has direct annotation
* instantiation) and should no longer be used.
*/
@Deprecated
@CheckReturnValue
@SuppressWarnings("unchecked") // Factories are required to return only matching JsonAdapters.
public <T> JsonAdapter<T> adapter(
Expand Down

0 comments on commit 9f81ac8

Please sign in to comment.