icubilla / jsonexserializer

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

JSONReader issue #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I need to read the Json string. And trying to find the value from many Key-
 Value pairs.
I am having a situation where in a base class is there and i am deriving 
various other classes from the base. 
I want to perform certain jobs and my extended classes are the various job 
types.
So depending on the job type the serializer is creating a different set of 
property and the property of the base class.

While reading i am not aware of which derividing class should i use to 
deserialze it back. I am trying with a base class then it gives me error.
since some of the metod he can not deserialize it.

How can add  i type information so that i can trace it back the proper 
derived type.

Or tell me the way to read the Json for any attribute at root level.

Original issue reported on code.google.com by supadhy...@gmail.com on 17 Jul 2008 at 1:24

GoogleCodeExporter commented 9 years ago
When you create the Serializer to serialize, pass in the base class type or
typeof(object) as the type, then do the same thing when you create the 
serializer to
deserialize.  You just need to ensure that the serializer is created the same 
way for
both serialization and deserialization.  The object type does not have to be the
actual object type of the class your are serializing, just a parent class of 
it. 
Example:

ChildClass c = new ChildClass();  // extends BaseClass

Serializer serializer = new Serializer(typeof(BaseClass));
string result = serializer.Serialize(c);

...

Serializer serializer = new Serializer(typeof(BaseClass));

ChildClass c = (ChildClass) serializer.Deserialize(someString);

Original comment by elliott....@gmail.com on 17 Jul 2008 at 1:33

GoogleCodeExporter commented 9 years ago
Your output for the above example should look like so:

(ChildClass) { 
   Prop1: "value"
}

Original comment by elliott....@gmail.com on 17 Jul 2008 at 1:39

GoogleCodeExporter commented 9 years ago

Original comment by elliott....@gmail.com on 6 Aug 2008 at 7:31