/** * @throws Exception If failed. */ @Test public void testCustomSerializer() throws Exception { BinaryTypeConfiguration type = new BinaryTypeConfiguration(CustomSerializedObject1.class.getName()); type.setSerializer(new CustomSerializer1()); BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type)); CustomSerializedObject1 obj1 = new CustomSerializedObject1(10); BinaryObject po1 = marshal(obj1, marsh); assertEquals(20, po1.<CustomSerializedObject1>deserialize().val); }
BinaryTypeConfiguration binTypCfg5 = new BinaryTypeConfiguration(EntityWriteReadObject.class.getName()); binTypCfg1.setSerializer(new BinaryReflectiveSerializer()); binTypCfg2.setSerializer(new BinaryReflectiveSerializer()); binTypCfg3.setSerializer(new BinaryReflectiveSerializer()); binTypCfg4.setSerializer(new BinaryReflectiveSerializer()); binTypCfg5.setSerializer(new BinaryReflectiveSerializer());
btcfg1.setSerializer(bs); "GridCacheBinaryObjectUserClassloaderSelfTest$TestValue1"); btcfg2.setSerializer(bs);
/** * @throws Exception If failed. */ @Test public void testCustomSerializerWithGlobal() throws Exception { BinaryTypeConfiguration type1 = new BinaryTypeConfiguration(CustomSerializedObject1.class.getName()); BinaryTypeConfiguration type2 = new BinaryTypeConfiguration(CustomSerializedObject2.class.getName()); type2.setSerializer(new CustomSerializer2()); BinaryMarshaller marsh = binaryMarshaller(new CustomSerializer1(), Arrays.asList(type1, type2)); CustomSerializedObject1 obj1 = new CustomSerializedObject1(10); BinaryObject po1 = marshal(obj1, marsh); assertEquals(20, po1.<CustomSerializedObject1>deserialize().val); CustomSerializedObject2 obj2 = new CustomSerializedObject2(10); BinaryObject po2 = marshal(obj2, marsh); assertEquals(30, po2.<CustomSerializedObject2>deserialize().val); }
btc.setSerializer(new BinarySerializer() { @Override public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); cfg.setConnectorConfiguration(new ConnectorConfiguration()); cfg.setMarshaller(new BinaryMarshaller()); BinaryConfiguration binaryCfg = new BinaryConfiguration(); BinaryTypeConfiguration btc = new BinaryTypeConfiguration("org.MyClass"); btc.setIdMapper(BinaryContext.defaultIdMapper()); btc.setEnum(false); // Set custom serializer that is unknown for Optimized marshaller. btc.setSerializer(new MyBinarySerializer()); binaryCfg.setTypeConfigurations(Collections.singletonList(btc)); cfg.setBinaryConfiguration(binaryCfg); // Set custom consistent ID that unknown for Optimized marshaller. cfg.setConsistentId(new MyConsistentId("test")); cfg.setCacheConfiguration(new CacheConfiguration("TEST")); return cfg; }