P.S. I realize that this is a major limitation.Ticket filed: https://issues.apache.org/jira/browse/IGNITE-10411
On Mon, Nov 26, 2018 at 7:54 PM Pavel Tupitsyn <[email protected]> wrote: > Yes, there is a mismatch there, Ignite passes uninitialized object to the > serializer in order to handle reference loops. > > I think the easiest workaround is to use some library like DeepClone [1]: > > public void ReadBinary(object obj, IBinaryReader reader) > { > if (obj is IBinarizable bin) > { > bin.ReadBinary(reader); > return; > } > > var res = reader.ReadObject<object>("x"); > res.ShallowCloneTo(obj); > } > > > [1] https://www.nuget.org/packages/DeepCloner/ > > > On Sat, Nov 24, 2018 at 11:56 AM Raymond Wilson < > [email protected]> wrote: > >> Yes, I want to throw exceptions essentially for all application types. >> Things like ephemeral exceptions I don't need serialization control over. >> >> Writing the object seems simple enough as you have suggested. >> >> However, reading it back is less simple due to the way IBinarySerializer >> calls ReadBinary in the context of the object. reader.ReadBinary() returns >> an instance which is at odds with the instance passed into >> IBinarySerializer.ReadBinary, so I'm not sure how to get reader.ReadObject >> to deserialize the state into the passed obj parameter. >> >> Thanks, >> Raymond. >> >> >> On Sat, Nov 24, 2018 at 6:41 AM Pavel Tupitsyn <[email protected]> >> wrote: >> >>> Sorry, I'm wrong. >>> You can of course just call writer.WriteObject(..) as a fallback, no >>> need for BinaryFormatter. >>> Your only goal is to throw exception for *some* types, right? >>> >>> On Fri, Nov 23, 2018 at 8:37 PM Pavel Tupitsyn <[email protected]> >>> wrote: >>> >>>> Hi Raymond, >>>> >>>> Exceptions implement ISerializable, and are serialized that way in >>>> Ignite. However, there is no "fallback" mechanism that you ask about (I >>>> should file a ticket, this is a good catch). >>>> >>>> So the workaround is to use .NET BinaryFormatter to serialize >>>> non-IBInarizable types and write them as byte array (WriteByteArray / >>>> ReadByteArray). >>>> Does this work for you? >>>> >>>> Thanks, >>>> Pavel >>>> >>>> On Fri, Nov 23, 2018 at 2:05 AM Raymond Wilson < >>>> [email protected]> wrote: >>>> >>>>> Hi Pavel, >>>>> >>>>> I have been using your suggestion with good effect. Thank you again >>>>> for suggesting it. >>>>> >>>>> I just ran into a case where an exception was thrown that stated >>>>> System.AggregateException could not be serialised within this class. >>>>> >>>>> While the BinarizableSerializer is good an ensuring all our >>>>> serialization contexts are covered with IBinarySerializer, it seems >>>>> obvious >>>>> that things like Exception derivatives can not be. How would you modify >>>>> this approach to make exceptions use the default reflective serialization? >>>>> >>>>> Thanks, >>>>> Raymond. >>>>> >>>>> >>>>> On Tue, Nov 13, 2018 at 9:20 AM Pavel Tupitsyn <[email protected]> >>>>> wrote: >>>>> >>>>>> Hi Raymond, >>>>>> >>>>>> Yes, you can do that by implementing IBinarySerializer like this: >>>>>> >>>>>> class BinarizableSerializer : IBinarySerializer >>>>>> { >>>>>> public void WriteBinary(object obj, IBinaryWriter writer) >>>>>> { >>>>>> if (obj is IBinarizable bin) >>>>>> { >>>>>> bin.WriteBinary(writer); >>>>>> } >>>>>> >>>>>> throw new Exception("Not IBinarizable: " + obj.GetType()); >>>>>> >>>>>> } >>>>>> >>>>>> public void ReadBinary(object obj, IBinaryReader reader) >>>>>> { >>>>>> if (obj is IBinarizable bin) >>>>>> { >>>>>> bin.ReadBinary(reader); >>>>>> } >>>>>> >>>>>> throw new Exception("Not IBinarizable: " + obj.GetType()); >>>>>> } >>>>>> } >>>>>> >>>>>> Then set it globally in IgniteConfiguration: >>>>>> >>>>>> var cfg = new IgniteConfiguration >>>>>> { >>>>>> BinaryConfiguration = new BinaryConfiguration >>>>>> { >>>>>> Serializer = new BinarizableSerializer() >>>>>> } >>>>>> }; >>>>>> >>>>>> >>>>>> >>>>>> On Thu, Nov 8, 2018 at 9:28 PM Raymond Wilson < >>>>>> [email protected]> wrote: >>>>>> >>>>>>> Hi Denis, >>>>>>> >>>>>>> Yes, I understand reflective serialisation uses binarizable >>>>>>> serialisation under the hood (and it's fast and easy to use). But it has >>>>>>> issues in the face of schema changes so it is better (and recommended in >>>>>>> the Ignite docs) to use Binarizable serialization for production. >>>>>>> >>>>>>> I want to make sure all my serialization contexts are covered by >>>>>>> explicit IBinarizable serialization. A simple approach would be to turn >>>>>>> off >>>>>>> reflective serialization to ensure cases where we have missed it fail >>>>>>> explicitly. Is that possible? >>>>>>> >>>>>>> Thanks, >>>>>>> Raymond. >>>>>>> >>>>>>> >>>>>>> On Thu, Nov 8, 2018 at 1:10 PM Denis Magda <[email protected]> >>>>>>> wrote: >>>>>>> >>>>>>>> Hi Raymond, >>>>>>>> >>>>>>>> If to believe this page, the reflective serialization converts an >>>>>>>> object to the binary format (sort of marked with IBaniralizable >>>>>>>> interface >>>>>>>> implicitly): >>>>>>>> >>>>>>>> https://apacheignite-net.readme.io/docs/serialization#section-ignite-reflective-serialization >>>>>>>> >>>>>>>> -- >>>>>>>> Denis >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Nov 6, 2018 at 1:01 PM Raymond Wilson < >>>>>>>> [email protected]> wrote: >>>>>>>> >>>>>>>>> We are currently converting our use of Ignite reflective >>>>>>>>> serialisation to use IBinarizable based serialisation [using Ignite >>>>>>>>> 2.6 >>>>>>>>> with c# client] >>>>>>>>> >>>>>>>>> What I would like to do is enforce a policy of not using >>>>>>>>> reflective serialisation to ensure we have all the bases covered. >>>>>>>>> >>>>>>>>> Is there a way to do this in Ignite? >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> Raymond. >>>>>>>>> >>>>>>>>>
