Serialize Appointment

2 posts, 0 answers
  1. Aziz
    Aziz avatar
    32 posts
    Member since:
    Sep 2011

    Posted 05 Apr 2012 Link to this post

    So I am using the schedule view control and have made a custom appointment type that extends Appointment.

    everything goes well except when i try to take this object and serilize it to json so i can send it to my rest service.

    i get the following error:

    "Type 'System.TimeZoneInfo' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required."



    here is how i am trying to serilize the object:

    public class Utils
        {
     
            public static string SerializeToJsonString(object objectToSerialize)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    DataContractJsonSerializer serializer =
                        new DataContractJsonSerializer(objectToSerialize.GetType());
                    serializer.WriteObject(ms, objectToSerialize);
                    ms.Position = 0;
                    using (StreamReader reader = new StreamReader(ms))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
        }


    any ideas?
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 10 Apr 2012 Link to this post

    Hi Jacob,

    What I would suggest you is to create your custom implementation of the IAppointment interface which has the all the properties except the TimeZone property and use it instead of the Appointment class. Alternatively you could serialize the Appointment object using different approach where you can specify which fields to serialize and which - not.

    Hope this helps.

    All the best,
    Miroslav Nedyalkov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
Back to Top