rubyamf/rubyamf — Issue #10: AMF Deserialization problem
Author: t-anjan
Created: 2011-12-07 06:32:30+00:00
State: open

I am a heavy user of AMF serialization and deserialization. Meaning, almost every one of my requests and responses will contain multiple and / or nested, associated models. With RubyAMF v1, all of this serialization and deserialization worked well.

But I seem to be having problems with RubyAMF v2 when it comes to nested models deserialization. When I send back an object of just one model type (with no associations), the deserialization seems to work fine. But when the request contains more complex objects, I receive a lot of `ActiveRecord::AssociationTypeMismatch` errors. A couple of examples:

```
ActiveRecord::AssociationTypeMismatch (Exam(#2205179320) expected, got Array(#2148433420))
```
```
ActiveRecord::AssociationTypeMismatch (MiniSubject(#2202173459) expected, got Date(#2157465432))
```

... where `Exam` and `MiniSubject` are models in my app. I use Charles as a local proxy to inspect my AMF calls. In Charles, I can see that the objects in my request body are of the correct types. No mismatch there. The `mini_subject` association had a `MiniSubject` object, not a Date.

I tried debugging and inspected the `props` variable in the `rubyamf/class_mapping.rb` file's `populate_ruby_obj` method. I saw that the `mini_subject` key in the `props` hash had a `Date` value. I have no idea how the gem has deserialized it into a date.

I just switched back to using RubyAMF v1 and the same request works flawlessly.

Let me know if you need any more help. When I get the time, I will try to make a sample app to reproduce the problem.