# Custom serialization problem (marshal\_dump, marshal\_load)

**URL:** <https://www.ruby-forum.com/t/custom-serialization-problem-marshal-dump-marshal-load/138296>\
**Category:** Rails\
**Created:** [May 21, 2008, 7:52pm UTC](https://www.ruby-forum.com/t/custom-serialization-problem-marshal-dump-marshal-load/138296 "2008-05-21T19:52:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [May 21, 2008, 7:52pm UTC](https://www.ruby-forum.com/t/custom-serialization-problem-marshal-dump-marshal-load/138296/1 "2008-05-21T19:52:56Z")

</div>

Hi,

I have a problem with the marshal\_dump and marshal\_load…  
I built two classes XXX, YYY and implemented both methods like this:

class YYY  
@data = “string”  
@version = 1

def marshal\_dump()  
return [@version,@data]  
end

def marshal\_load(var)  
@version = var[0]  
case @version  
when 1  
@data = var[1]  
else  
#do something else  
end  
end  
end

class XXX  
@data = Array of YYY  
@version = 1

def marshal\_dump()  
return [@version,@data]  
end

def marshal\_load(var)  
@version = var[0]  
case @version  
when 1  
@data = var[1]  
else  
#do something else  
end  
end  
end

The serialization works correctly when the number of objects YYY is  
small, but when it got more than 5000, the serialization doesn’t work.  
(the serializaed file has more and less 1 meg)

When I try to not to use marshal\_dump and marshal\_load. the  
serialization works again???

Can someone tell me, where is the difference between customized  
serialization and no-customized one???

Thanks you very much

Sayoyo

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [May 21, 2008, 10:18pm UTC](https://www.ruby-forum.com/t/custom-serialization-problem-marshal-dump-marshal-load/138296/2 "2008-05-21T22:18:13Z")

</div>

On 21 May 2008, at 18:52, sayoyo Sayoyo wrote:

> The serialization works correctly when the number of objects YYY is  
> small, but when it got more than 5000, the serialization doesn’t work.  
> (the serializaed file has more and less 1 meg)

Asking smart questions, lesson 1. Never say “it doesn’t work”. Do say  
exactly what happens and how that differs from what you expected.

Fred
