Conversation
Adds Kotlin array support to the bson-kotlin library JAVA-5122
| } | ||
| } | ||
| val codec = | ||
| if (nestedTypes.isEmpty()) codecRegistry.get(valueClass) else codecRegistry.get(valueClass, nestedTypes) |
There was a problem hiding this comment.
Just a question: Is it our Kotlin code style to use single-line if-else statements without braces?
There was a problem hiding this comment.
Yes, we follow the main kotlin coding standards.
See: https://kotlinlang.org/docs/control-flow.html#if-expression
It looks unusual as in Java we'd use a tenary operator but in Kotlin there is no such thing.
bson-kotlin/src/main/kotlin/org/bson/codecs/kotlin/ArrayCodec.kt
Outdated
Show resolved
Hide resolved
| if (typeArguments.isEmpty()) { | ||
| Pair(kClass.java.componentType.kotlin.javaObjectType as Class<Any>, emptyList()) | ||
| } else { | ||
| when (val pType = typeArguments[0]) { | ||
| is Class<*> -> Pair(pType as Class<Any>, emptyList()) | ||
| is ParameterizedType -> Pair(pType.rawType as Class<Any>, pType.actualTypeArguments.toList()) | ||
| else -> Pair(Object::class.java as Class<Any>, emptyList()) | ||
| } | ||
| } |
There was a problem hiding this comment.
[Optional] We could consider extracting this code block into a named method to enhance clarity.
There was a problem hiding this comment.
As its a single block, I opted to add a comment instead.
| if (!isPrimitiveArray) { | ||
| (arrayValue as Array<V?>).iterator() | ||
| } else if (arrayValue is BooleanArray) { | ||
| arrayValue.toList().iterator() |
There was a problem hiding this comment.
Using toList() seems redundant since we can directly use an iterator on the array itself. Is this additional conversion to a List necessary?
There was a problem hiding this comment.
It was used to stop a spotbugs error, however, using asIterable works without triggering the error.
|
Thanks @vbabanin the when block looks much better |
Adds Kotlin array support to the bson-kotlin library JAVA-5122 Co-authored-by: Viacheslav Babanin <[email protected]>
Adds Kotlin array support to the bson-kotlin library JAVA-5122 Co-authored-by: Viacheslav Babanin <[email protected]>
Adds Kotlin array support to the bson-kotlin library
JAVA-5122