Question

Lets assume following is my object model:

Person {
String name;
List<Address> addressesList;
}

Address 
{
String field1;
String field2;
}

I am trying to serialize the Person object using flex JSon Serializer. I have some limit on the size of the serialized object, which can't be exceeded. What I want to do is truncate the addressesList (serilaize the less number of addresses), so that limit isn't exceeded. I am wondering if there is way aforementioned use case can be be implemented ?

Thanks

No correct solution

OTHER TIPS

Sure -- you can do this by adding your addresses one at a time and checking to see whether you have exceeded your limit. (Save each "still good" string and revert if needed). Creating the full JSON text and removing addresses one by one from the last address is another alternative ... but the logic might be more difficult.

If you hit the size limitation rarely, you could use the following strategy:

  • Serialize the Person object
  • if within limits return
  • Otherwise recreate the person object with one less address, reserialize and check
  • repeat as neccessary.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top