tags:

views:

53

answers:

2

What happens when I annotate a class with serializable? Can I serialize them into json or XML? How is this done?

A: 

This allows the class to be serialized with the available serializers, like xmlserializer and the binary serializer. However, more annotations are probably required to output it in the desired xml layout (or JSON)

Documentation

WardB
`XmlSerializer` does not care about `SerializableAttribute`.
Matti Virkkunen
Yep, you are right. It's only the binary serializer.
WardB
+2  A: 

The SerializableAttribute is just a marker attribute that does nothing.

When using it, you are claiming that every component of your class can be serialized - in order to actually serialize the class you need to use a serializer such as the XmlSerializer or DataContractSerializer.

To use the DataContractSerializer, you need to decorate your classes and class members with different attributes (DateMemberAttribute, for example). It give you better control over the output XML than the XmlSerializer does and can also output JSON.

Oded
It's not a marker interface, because it's not an interface. It's an attribute.
Matti Virkkunen
I think he's referring to the general term where it's a run time marker.
Preet Sangha