I'm assuming this is protobuf-net; the message is right : the library
can't work with "object itemField". Perhaps the best thing would be to
treat this like a "oneof" (in .proto terms) and have an accessor per
possible type. For example:

    [ProtoMember(n)]
    private int ValueInt32 {
        get => (int)itemField;
        set => itemField = value;
    }
    private bool ShouldSerializeValueInt32() => itemField is int;

(with a different "n" per possible type)

The "ShouldSerialize..." pattern is a .net idiom supported by protobuf-net
that provides memberwise conditional serialization.



On 23 Oct 2017 8:07 a.m., "Nihar Mishra" <[email protected]> wrote:

>
> Hi,
>
> I have below class which is generated from .net client.
> When i try to save in redis cache, i get the "Not able to serialize Object
> type" error.
> Please help me how to resolve it.
>
>   public partial class AttributeValueType
>     {
>         [DataMember]
>         private object itemField;
>
>
>         [System.Xml.Serialization.XmlElementAttribute("IntValue",
> typeof(int))]
>         [System.Xml.Serialization.XmlElementAttribute("StringValue",
> typeof(string))]
>         [System.Xml.Serialization.XmlElementAttribute("dateValue",
> typeof(System.DateTime), DataType = "date")]
>         [System.Xml.Serialization.XmlElementAttribute("doubleValue",
> typeof(double))]
>         public object Item
>         {
>             get { return this.itemField; }
>             set { this.itemField = value; }
>         }
>     }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to