/** * Gets the Java filter if present. * * @param filter Filter object. * @param ctx Context. * @return Java filter or null. */ private static CacheEntryEventFilter getJavaFilter(Object filter, GridKernalContext ctx) { if (filter instanceof BinaryObjectImpl) { BinaryObjectImpl bo = (BinaryObjectImpl)filter; if (bo.typeId() == GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY) { PlatformJavaObjectFactoryProxy prx = bo.deserialize(); return (CacheEntryEventFilter)prx.factory(ctx).create(); } } return null; }
/** {@inheritDoc} */ @Override public void serialize(BinaryObjectImpl bin, JsonGenerator gen, SerializerProvider ser) throws IOException { try { BinaryType meta = bin.rawType(); // Serialize to JSON if we have metadata. if (meta != null && !F.isEmpty(meta.fieldNames())) { gen.writeStartObject(); for (String name : meta.fieldNames()) { Object val = bin.field(name); if (val instanceof BinaryObjectImpl) { BinaryObjectImpl ref = (BinaryObjectImpl)val; if (ref.hasCircularReferences()) throw ser.mappingException("Failed convert to JSON object for circular references"); } gen.writeObjectField(name, val); } gen.writeEndObject(); } else { // Otherwise serialize as Java object. Object obj = bin.deserialize(); gen.writeObject(obj); } } catch (BinaryObjectException ignore) { gen.writeNull(); } } };
/** * */ @Test public void testReadResolveOnBinaryAware() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Collections.singletonList( new BinaryTypeConfiguration(MyTestClass.class.getName()))); BinaryObjectImpl binaryObj = marshal(new MyTestClass(), marsh); MyTestClass obj = binaryObj.deserialize(); assertEquals("readResolve", obj.s); }
/** * */ @Test public void testReadResolve() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(MySingleton.class.getName()), new BinaryTypeConfiguration(SingletonMarker.class.getName()))); BinaryObjectImpl binaryObj = marshal(MySingleton.INSTANCE, marsh); assertTrue(binaryObj.array().length <= 1024); // Check that big string was not serialized. MySingleton singleton = binaryObj.deserialize(); assertSame(MySingleton.INSTANCE, singleton); }
/** * @throws Exception If failed. */ @Test public void testKeepDeserialized() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName()))); BinaryObjectImpl po = marshal(simpleObject(), marsh); CacheObjectContext coCtx = new CacheObjectContext(newContext(), null, null, false, false, true, false, false); assert po.value(coCtx, false) == po.value(coCtx, false); po = marshal(simpleObject(), marsh); assert po.deserialize() != po.deserialize(); }
b.deserialize(); // deserialize working b.deserialize();
new DetachedInnerTestObject(null, id)), marsh).deserialize(); DetachedInnerTestObject inner = innerPo.deserialize(); inner = detachedPo.deserialize(); inner = innerPo.deserialize(); inner = innerPo.deserialize();
/** * @throws Exception If failed. */ @Test public void testDefaultMapping() throws Exception { BinaryTypeConfiguration customMappingType = new BinaryTypeConfiguration(TestBinary.class.getName()); customMappingType.setIdMapper(new BinaryIdMapper() { @Override public int typeId(String clsName) { String typeName = BinaryContext.SIMPLE_NAME_LOWER_CASE_MAPPER.typeName(clsName); return typeName.toLowerCase().hashCode(); } @Override public int fieldId(int typeId, String fieldName) { return fieldName.toLowerCase().hashCode(); } }); BinaryMarshaller marsh1 = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()), customMappingType )); TestBinary obj = binaryObject(); BinaryObjectImpl po = marshal(obj, marsh1); BinaryMarshaller marsh2 = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()), new BinaryTypeConfiguration(TestBinary.class.getName()) )); po = marshal(obj, marsh2); assertEquals(obj, po.deserialize()); }
assertArrayEquals(obj1.valArr, portObj.<DecimalReflective>deserialize().valArr); assertArrayEquals(obj1.valArr, (BigDecimal[])portObj.type().field("valArr").value(portObj)); assertEquals(obj1.val, portObj.<DecimalReflective>deserialize().val); assertEquals(obj1.val, portObj.type().field("val").value(portObj)); assertArrayEquals(obj2.valArr, portObj.<BigDecimal[]>field("valArr")); assertEquals(obj2.val, portObj.<DecimalMarshalAware>deserialize().val); assertArrayEquals(obj2.valArr, portObj.<DecimalMarshalAware>deserialize().valArr); assertEquals(obj2.rawVal, portObj.<DecimalMarshalAware>deserialize().rawVal); assertArrayEquals(obj2.rawValArr, portObj.<DecimalMarshalAware>deserialize().rawValArr); assertEquals(obj2.val, portObj.<DecimalMarshalAware>deserialize().val); assertEquals(obj2.val, portObj.type().field("val").value(portObj));
DuplicateFieldsB deserialized = objBin.deserialize();
/** * Gets the Java filter if present. * * @param filter Filter object. * @param ctx Context. * @return Java filter or null. */ private static CacheEntryEventFilter getJavaFilter(Object filter, GridKernalContext ctx) { if (filter instanceof BinaryObjectImpl) { BinaryObjectImpl bo = (BinaryObjectImpl)filter; if (bo.typeId() == GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY) { PlatformJavaObjectFactoryProxy prx = bo.deserialize(); return (CacheEntryEventFilter)prx.factory(ctx).create(); } } return null; }