Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 249166

Re: Testing a custom PdxSerializer

$
0
0

Oh, sorry. You'll still need the cache with this code. Here is a full example.

 

cache.xml:

 

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE cache PUBLIC  "-//GemStone Systems, Inc.//GemFire Declarative Caching 6.6//EN"  "http://www.gemstone.com/dtd/cache6_6.dtd">  <cache>  <pdx read-serialized="true">    <pdx-serializer>      <class-name>com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer</class-name>      <parameter name="classes">        <string>Trade</string>      </parameter>    </pdx-serializer>  </pdx></cache>

 

Simple test method:

 

privatevoid testPdxSerialization() throws Exception {  // Create object  Trade trade = new Trade("MHS", "MHS", 100, 55.33);  System.out.println("Created: " + trade);   // Write the object using the PDX serializer (defined in cache.xml)  byte[] serializedValue = BlobHelper.serializeToBlob(trade);   // Deserialize the pdx instance and trade (read-serialized="true")  PdxInstance tradePdxInstance = (PdxInstance) BlobHelper.deserializeBlob(serializedValue);  Trade deserializedTrade = (Trade) tradePdxInstance.getObject();  System.out.println("Deserialized: " + deserializedTrade);   // Compare trades  System.out.println("Trades are equal: " + trade.equals(deserializedTrade));}


Viewing all articles
Browse latest Browse all 249166

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>