Dev: fix AnyCodable basic type decoding
This commit is contained in:
parent
3b4391a193
commit
6883ee4c5c
|
@ -31,6 +31,15 @@ public struct JavaCoderConfig {
|
|||
decodableClosures[typeName] = decodableClosure
|
||||
}
|
||||
|
||||
public static func typeName(from className: String) -> String? {
|
||||
for (typeName, registeredClassName) in codableClassNames {
|
||||
if registeredClassName == className {
|
||||
return typeName
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public static func RegisterBasicJavaTypes() {
|
||||
|
||||
RegisterType(type: Int.self, javaClassname: IntegerClassname, encodableClosure: {
|
||||
|
|
|
@ -560,8 +560,16 @@ fileprivate class JavaAnyCodableContainer<K : CodingKey> : KeyedDecodingContaine
|
|||
if key.stringValue == "typeName" {
|
||||
switch jniCodableType {
|
||||
case let .object(className):
|
||||
let subString = className.split(separator: "/").last!
|
||||
return String(subString) as! T
|
||||
let typeName: String
|
||||
// Check if classname registered in JavaCoderConfig
|
||||
if let defaultTypeName = JavaCoderConfig.typeName(from: className) {
|
||||
typeName = defaultTypeName
|
||||
}
|
||||
// if not use ClassName as Swift type name
|
||||
else {
|
||||
typeName = String(className.split(separator: "/").last!)
|
||||
}
|
||||
return typeName as! T
|
||||
case .array:
|
||||
return AnyCodable.ArrayTypeName as! T
|
||||
case .dictionary:
|
||||
|
|
Loading…
Reference in New Issue