You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
I have a class B which inherits from a super class A:
class A: Juice.Decodable {
var a: String?
required init(fromJson json: Juice.JSONDictionary) throws {
a = try? json.decode(["a"])
}
}
class B: A {
var b: String?
required init(fromJson json: Juice.JSONDictionary) throws {
b = try? json.decode(["b"])
try super.init(fromJson: json)
}
}
When I decode B (in my case an array of B's (not shown in this reduced example)) I get an exception from deep inside of Juice.
Example code:
// Decoding simple object B -> Works
do {
let string = "{\"a\": \"Apple 0\", \"b\": \"Brother 0\"}"
let dict = try toStrictlyTypedJSON(toLooselyTypedJSON(string)) as! JSONDictionary
let o = try B(fromJson: dict)
print(o.a, o.b)
} catch {
print(error.localizedDescription)
}
// B as a part of an object -> Fails
do {
let string = "{\"object\": {\"a\": \"Apple 1\", \"b\": \"Brother 1\"}}"
let dict = try toStrictlyTypedJSON(toLooselyTypedJSON(string)) as! JSONDictionary
// This works
let oa: A = try dict.decode("object")
print(oa.a)
// This fails with exception "Could not cast value of type 'A' to 'B'"
let ob: B = try dict.decode("object")
print(ob.a, ob.b)
} catch {
print(error.localizedDescription)
}
My knowledge of generics is a bit to shallow to find the reason.
All the best
The text was updated successfully, but these errors were encountered:
Hi thanks for the updated version 1.0.9.
I just stumbled upon another issue with Juice.
I have a class
B
which inherits from a super classA
:When I decode B (in my case an array of B's (not shown in this reduced example)) I get an exception from deep inside of Juice.
Example code:
My knowledge of generics is a bit to shallow to find the reason.
All the best
The text was updated successfully, but these errors were encountered: