icubilla / jsonexserializer

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

Public Members do not serialized #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Example of my problem:
say I have the following couple of classes

public class Hdr {
    public string A {get { return "A"; }}
}

public class Msg {
    public Hdr Header = new Hdr();
    public string Body {get{ return "Message";}}
    public Msg(){}
}

Calling:

Serializer ser = new Serializer(typeof(Msg));
Console.WriteLine(ser.Serialize(new Msg()));

Yields Msg.Headr -> Null.

Original issue reported on code.google.com by Afro.Sys...@gmail.com on 12 Jun 2008 at 5:43

GoogleCodeExporter commented 9 years ago
Properties are expected to have a Getter and a Setter in order to be serialized
otherwise deserialization will fail.  The "A" property on header has no setter 
so its
not serialized.  You can add the "JsonExProperty" attribute to the property to 
force
it to serialize.

Example:
public class Hdr {
    [JsonExProperty]
    public string A {get { return "A"; }}
}

How are you using this?  Are you doing only serialization, sending to a browser 
perhaps?

Original comment by elliott....@gmail.com on 22 Jun 2008 at 1:05

GoogleCodeExporter commented 9 years ago
thank you very much for this information.
(I would add this to the quickstat wiki page).

> How are you using this?  Are you doing only serialization, sending to a 
browser
perhaps?

That's right, some data is read only so object designed accordingly. 

Original comment by Afro.Sys...@gmail.com on 22 Jun 2008 at 3:37

GoogleCodeExporter commented 9 years ago
yet,
if the property is primitive (such as int) it fails @ 
metadata.proprtyhandler.validate.
any suggest how to hack this design?

Original comment by Afro.Sys...@gmail.com on 22 Jun 2008 at 9:29

GoogleCodeExporter commented 9 years ago
I could probably remove that validation.  In the meantime you might be able to 
get
away with declaring a private or internal setter, although I'm not totally sure 
that
it still won't flag it as not being writable.  Example:
public class Hdr {
    [JsonExProperty]
    public string A {
       get { return "A"; }
       private set { ; }
    }
}

Original comment by elliott....@gmail.com on 23 Jun 2008 at 1:55

GoogleCodeExporter commented 9 years ago
I set this (empty) private setter and it works!
thanks for writing this efficient library for us --- 

Original comment by Afro.Sys...@gmail.com on 24 Jun 2008 at 7:54

GoogleCodeExporter commented 9 years ago
The validation to check for the property to be writable when using the 
JsonExProperty
attribute has been removed.

Original comment by elliott....@gmail.com on 2 Jul 2008 at 10:19

GoogleCodeExporter commented 9 years ago

Original comment by elliott....@gmail.com on 2 Jul 2008 at 10:21

GoogleCodeExporter commented 9 years ago

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