icubilla / jsonexserializer

Automatically exported from code.google.com/p/jsonexserializer
0 stars 0 forks source link

Provide for TypeConversion #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Allow for type conversion to convert an object to a more-suitable type for
serialization.

A converter can be specified in several different ways.  The forms are
list in order of precedence.  This order will be used in the
event that multiple converters exist for a given entity:
1. Registering a converter with the serializer instance.
Example: serializer.Context.RegisterConverter(typeof(MyObject), new
MyObjectConverter());

2. a converter attribute at the property level
[JsonConverter(typeof(SomeConverter))]
public string MyProp { get { ... } set { ... } }

3. a converter attribute at the class level
[JsonConverter(typeof(SomeConverter))]
class MyClass { ...

4. using System.ComponentModel.TypeConverterAttribute
This will only allow conversion to primitive types such as strings or number

- Converters should either implement an IConverter interface or provide an
AbstractBaseConverter abstract base class, depending upon which is the best
approach.

Converters can be chained by specifying the JsonConverter attribute
multiple times.  This will be implemented using a ChainedConverter class
instance.  This same class can be passed to the Register method as well.

Original issue reported on code.google.com by elliott....@gmail.com on 6 Jun 2007 at 2:28

GoogleCodeExporter commented 9 years ago
Some useful converters should be provided with the library.  One example would 
be a
DictionaryToListConverter.  Useful in a situation where a dictionary of objects 
uses
a key that is a property of the value object.  On serialization the Values 
collection
of the Dictionary would be returned as the Converted object.  Upon 
deserialization, a
key property is specified and that value is read from the objects coming in and 
used
to construct the dictionary instance to be returned.

Original comment by elliott....@gmail.com on 6 Jun 2007 at 2:31

GoogleCodeExporter commented 9 years ago

Original comment by elliott....@gmail.com on 16 Jun 2007 at 8:09

GoogleCodeExporter commented 9 years ago
Supplying multiple convert attributes to create a chained converter turned out 
to not
be feasible since Attributes are returned through reflection in an unspecified 
order.
 Since a chained converter would depend on the order to work correctly, it couldn't
be done in this way.

Original comment by elliott....@gmail.com on 1 Aug 2007 at 7:57

GoogleCodeExporter commented 9 years ago

Original comment by elliott....@gmail.com on 10 Jul 2008 at 5:01