Geode native client deserialise PdxInstanceImpl

若如初见. 提交于 2019-12-11 00:16:05

问题


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...



来源:https://stackoverflow.com/questions/45568028/geode-native-client-deserialise-pdxinstanceimpl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!