Weebly / Cereal

Swift object serialization
BSD 3-Clause "New" or "Revised" License
369 stars 13 forks source link

Cereal failing to decode data that it encoded successfully #24

Open einsteinx2 opened 7 years ago

einsteinx2 commented 7 years ago

Hi, I'm currently using Cereal 1.4.0 in a Swift 3 project on OS X ( I created an OS X target, which has been working fine for me so far, with the exception of this issue).

I'm not sure if my recent upgrade to Swift 3 and Cereal 1.4.0 introduced this issue, or not, because I'm sure it worked previously but not sure exactly when it stopped working.

Anyway, I'm serializing an array of Swift objects, in this case the array includes only one object.

The error I'm getting is ".Array / .Cereal / .Dictionary not expected", so of course at first I thought the problem was that I was deserializing an array (even though that should be supported). However on closer inspection, the issue is with the decoding of a property in the object which is a dictionary. parseEncodedDictionaryString is being called, which calls iterateEncodedValues, which eventually calls parseEncodedDictionaryString. This then fails decoding the key, apparently because the key's type is .cereal.

Here's all the data that's failing in parseEncodedDictionaryString:

keyType = CerealOSX.CerealTypeIdentifier.cereal keyValue = "k,8:rawValue:s,4:more" type = CerealOSX.CerealTypeIdentifier.string value = "100"

Any idea why this is failing? Also what does the key type of .cereal mean and why is that unexpected? I'm getting no errors during the encoding/serialization, only in decoding. Is this a bug in Cereal, or something I'm doing wrong?

Any help is greatly appreciated, thanks!

ladvoc commented 7 years ago

Same issue.

einsteinx2 commented 7 years ago

Never figured out a fix, ended up just not using Cereal.

tengyifei commented 7 years ago

try cerealDecode instead of decode