Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected type MarshaledObject for key: node. Got 'Optional<Any>' #145

Open
JetForMe opened this issue Jun 24, 2021 · 1 comment
Open

Expected type MarshaledObject for key: node. Got 'Optional<Any>' #145

JetForMe opened this issue Jun 24, 2021 · 1 comment

Comments

@JetForMe
Copy link
Contributor

JetForMe commented Jun 24, 2021

I love Marshal and I'm a bit worried that maybe it's been abandoned, but hopefully you can help me with this:

I've lately started running into this error: Expected type MarshaledObject for key: node. Got 'Optional<Any>'. I can cast the object to [String:Any], but not to [MarshaledObject].

The failure is happening in Unmarshaling.swift:

extension Unmarshaling {
    
    public static func value(from object: Any) throws -> ConvertibleType {
        guard let convertedObject = object as? MarshaledObject else {
            throw MarshalError.typeMismatch(expected: MarshaledObject.self, actual: type(of: object))
        }
        guard let value = try self.init(object: convertedObject) as? ConvertibleType else {
            throw MarshalError.typeMismatch(expected: ConvertibleType.self, actual: type(of: object))
        }
        return value
    }
    
}

If I print the type of the object in the debugger, it's:

(lldb) po type(of: any)
Swift.Optional<Any>

In the debugger it looks like this:

Screen Shot 2021-06-23 at 18 12 07

Swift 5 in Xcode 13b, but also happens in 12.5.1

Thanks!

@JetForMe
Copy link
Contributor Author

Yeah, I think problem is the Anys are actually Optional<Any>s, and Marshal doesn't like that. I’m not quite sure how to make it handle those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant