|Number of votes:||1|
When working on getting EPiImage to work in EPiServer 7 I ran into the following error when publishing or auto saving an EPiImageGalleryProperty.
From the error message I guessed it had something to do with the JSON communication used in the new UI.
Turns out that since EPiImageGalleryProperty stores its data as an EPiImageGalleryImageCollection object, EPiServer 7 doesn’t know how to serialize it as a JSON object. But how can we tell EPiServer explicitly how to do the serialization?
Luckily Linus Ekström (EPiServer Sweden) helped me out with some sample code:
This class which inherits from JsonConverter tells EPiServer 7 how to do the conversion of a EPiServer.Url to Json (meaning a string representation) and back again.
I can create my own Json converter for EPiImageGalleryImageCollection like this:
For it to work I also needed to do the following changes to my existing EPiImage code:
1. Create a ToString method for EPiImageGalleryImageCollection that accurately serialized the data in the object to a string. As it consists of a List<EPiImageGalleryImage> I also need to:
2. Create a ToString method for EPiImageGalleryImage that accurately serialized the data in the object to a string
3. Create a constructor method for EPiImageGalleryImageCollection that could take in the serialized string as a parameter to recreate the object
4. Create a constructor method for EPiImageGalleryImage that could take in the serialized string as a parameter to recreate the object
If you are converting your own custom property to work with EPiServer 7, I thought this code might guide you in the right direction