我有一個REST客戶端,它使用Json數據填充Geode區域,Geode REST API自動轉換爲PdxInstance類型。Geode本地客戶端反序列化PdxInstanceImpl
該地區觸發該TVal
型ev.NewValue
被視爲PdxInstanceImpl
類型和看起來像一個C#本地客戶端偵聽AfterCreate(EntryEvent<TKey, TVal> ev)
:
PDX[7534066,__GEMFIRE_JSON]{@type=MyClass, Field1=Value1, Field2=Value2}
我從here看到下面的代碼可以得到個人Pdx字段
IPdxInstance pdx = (IPdxInstance)ev.NewValue;
pdx.GetField("Field1");
和那在字段級別,但我想要轉換PdxInstanceImpl
收到PdxInstance
,所以它可以直接放入另一個區域,或者我想將所有字段轉換回JSON(作爲一個字符串),然後將Json字符串放入另一個區域,或者像我喜歡的那樣使用它。
因此,有顯然是一個autoserialize到PdxInstance
一個MyClass
的方式,但如果我嘗試
MyClass c = (MyClass)pdx;
然後我得到System.InvalidCastException: Unable to cast object of type 'Apache.Geode.Client.Internal.PdxInstanceImpl' to type 'MyClass'
我從一些Java client examples看到您可以使用類型PdxInstanceImpl
來獲取數據,但在C#本地客戶端中出現錯誤:PdxInstanceImpl is inaccessible due to its protection level
。
我已經添加了autoserializer,結果是一樣的。
任何想法我在這裏失蹤?感謝
pdx.GetObject()導致'{System.NullReferenceException:未設置爲一個對象的實例對象引用。 在System.Object.GetType() 在Apache.Geode.Client.ReflectionBasedAutoSerializer.deserializeFields(字符串O,IPdxReader讀取器) 在Apache.Geode.Client.PdxWrapper.FromData(IPdxReader讀取器) 在Apache.Geode.Client。 Internal.PdxHelper.DeserializePdx(DataInput dataInput,布爾forceDeserialize,Int32 typeId,Int32長度) at Apache.Geode.Client.Internal.PdxInstanceImpl.GetObject()}' – rupweb