Skip to content

Commit

Permalink
Merge pull request #71 from ProjectMapK/fix-for-#70
Browse files Browse the repository at this point in the history
Fix for #70
  • Loading branch information
k163377 authored Feb 15, 2023
2 parents d1ffdce + d1eb1f1 commit e72266d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ internal class ReflectionCache(reflectionCacheSize: Int) {
)
} // we cannot reflect this method so do the default Java-ish behavior

private fun AnnotatedMethod.findValueClassBoxConverter(): ValueClassBoxConverter<*, *>? {
val getter = this.member.apply {
// If the return value of the getter is a value class,
// it will be serialized properly without doing anything.
// TODO: Verify the case where a value class encompasses another value class.
if (this.returnType.isUnboxableValueClass()) return null
}
val kotlinProperty = getKmClass(getter.declaringClass)?.findPropertyByGetter(getter)

// Since there was no way to directly determine whether returnType is a value class or not,
// Class is restored and processed.
return kotlinProperty?.returnType?.reconstructClassOrNull()?.let { clazz ->
clazz.takeIf { it.isUnboxableValueClass() }
?.let { ValueClassBoxConverter(getter.returnType, it) }
}
}

private fun AnnotatedMethod.getValueClassReturnType(): Class<*>? {
val getter = this.member.apply {
// If the return value of the getter is a value class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ internal class KotlinFallbackAnnotationIntrospector(
cache.findValueClassReturnType(a)?.let { cache.getValueClassBoxConverter(a.rawReturnType, it) }
}

// Determine if the `unbox` result of `value class` is `nullable
// Determine if the unbox result of value class is nullable
// @see findNullSerializer
private fun Class<*>.requireRebox(): Boolean = isUnboxableValueClass() &&
private fun Class<*>.requireRebox(): Boolean =
cache.getKmClass(this)!!.properties.first { it.fieldSignature != null }.returnType.isNullable()

// Perform proper serialization even if the value wrapped by the value class is null.
Expand Down

0 comments on commit e72266d

Please sign in to comment.