@@ -229,6 +229,7 @@ internal fun getConverter(from: KType, to: KType, options: ParserOptions? = null
229229 convertersCache.getOrPut(Triple (from, to, options)) { createConverter(from, to, options) }
230230
231231internal typealias TypeConverter = (Any ) -> Any?
232+ private val TypeConverterIdentity : TypeConverter = { it }
232233
233234internal fun Any.convertTo (type : KType ): Any? {
234235 val clazz = javaClass.kotlin
@@ -250,25 +251,24 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
250251 }
251252 val fromClass = from.jvmErasure
252253 val toClass = to.jvmErasure
254+ return when {
255+ fromClass == toClass -> TypeConverterIdentity
253256
254- if (fromClass == toClass) return { it }
255-
256- if ( toClass.isValue) {
257- val constructor =
258- toClass.primaryConstructor ? : error( " Value type $toClass doesn't have primary constructor " )
259- val underlyingType = constructor .parameters.single().type
260- val converter = getConverter(from, underlyingType)
261- ? : throw TypeConverterNotFoundException (from, underlyingType, null )
262- return convert< Any > {
263- val converted = converter (it)
264- if (converted == null && ! underlyingType.isMarkedNullable) {
265- throw TypeConversionException (it, from, underlyingType, null )
257+ toClass.isValue -> {
258+ val constructor =
259+ toClass.primaryConstructor ? : error( " Value type $toClass doesn't have primary constructor " )
260+ val underlyingType = constructor .parameters.single().type
261+ val converter = getConverter(from, underlyingType )
262+ ? : throw TypeConverterNotFoundException (from, underlyingType, null )
263+ return convert< Any > {
264+ val converted = converter(it )
265+ if (converted == null && ! underlyingType.isMarkedNullable) {
266+ throw TypeConversionException (it, from, underlyingType, null )
267+ }
268+ constructor .call(converted )
266269 }
267- constructor .call(converted)
268270 }
269- }
270271
271- return when {
272272 fromClass == String ::class -> {
273273 val parser = Parsers [to.withNullability(false )]
274274 when {
0 commit comments