nemo
nemo

Reputation: 485

Why do I get an error when deserializing a Ruby object?

I have the following Ruby map object serialized at one end and received at the other. When received at the target, I need to evaluate it back to the same map object as the original and do some processing.

However, evaluation at the target fails with a "syntax error, unexpected $end" msg.

It fails because the :application symbol refers to an UploadIO object.

Given that I can only change the code on the target where I receive the serialized object, what is the best way to resolve the issue? Convert the value of :application to a string or use some other trick?

eval ('
 {"component"=>"CF", 
  "body"=>
    ["PUT", 
     "v2/apps/269e739c-5d08-429c-8682-d3200b79283b/bits", 
     {:payload=>
       {
       :resources=>"[]", 
       :application=>#<UploadIO:0x000000022af330 @content_type="application/zip">
       }
     }
    ]
 }')

Upvotes: 0

Views: 100

Answers (1)

Peter Alfvin
Peter Alfvin

Reputation: 29419

You can't reasonably do an eval on the string as is, because the # is being processed as a comment character. The most straightforward approach would be to go ahead and replace the occurrences of #<...> in the string with whatever you want in their place prior to doing the eval.

Upvotes: 2

Related Questions