This is a migrated thread and some comments may be shown as answers.
Serialize Appointment
1 Answer 27 Views
This is a migrated thread and some comments may be shown as answers.
Aziz
Top achievements
Rank 1
Aziz asked on 05 Apr 2012, 08:28 PM
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?

1 Answer, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 10 Apr 2012, 12:14 PM
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 >>

Asked by
Aziz
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Share this question
or