Geode native client deserialise PdxInstanceImpl

2019-07-20 16:14发布

问题:

I have a REST client that populates a Geode region with Json data which the Geode REST API automatically converts to a PdxInstance type.

The region triggers a C# native client listener AfterCreate(EntryEvent<TKey, TVal> ev) in which the TVal type ev.NewValue is seen as type PdxInstanceImpl and looks like:

PDX[7534066,__GEMFIRE_JSON]{@type=MyClass, Field1=Value1, Field2=Value2}

I've seen from here that the following code can get at the individual Pdx fields

IPdxInstance pdx = (IPdxInstance)ev.NewValue;
pdx.GetField("Field1");

and that works on a Field level, but I want to convert the PdxInstanceImpl that is received to PdxInstance so it can be put into another region directly, or I want to convert all the fields back to Json (as a string) in 1 go and put a Json string into another region, or use it as I like.

So there is apparently a way to autoserialize a PdxInstance to MyClass but if I try

MyClass c = (MyClass)pdx;

then I get System.InvalidCastException: Unable to cast object of type 'Apache.Geode.Client.Internal.PdxInstanceImpl' to type 'MyClass'

I've seen from some Java client examples you can use type PdxInstanceImpl to get at the data but in the C# native client that gives an error: PdxInstanceImpl is inaccessible due to its protection level.

I've added the autoserializer and the results are the same.

Any idea what I am missing here? Thanks

回答1:

In the end I've used a field by field approach:

IPdxInstance pdx = (IPdxInstance)ev.NewValue; pdx.GetField("Field1"); pdx.GetField("Field2"); pdx.GetField("Field3"); etc...