@Test public void rejectUnexpectedClass() throws Exception { final ByteArrayOutputStream boas = new ByteArrayOutputStream(); try (final ObjectOutputStream oos = new ObjectOutputStream(boas)) { oos.writeObject(new ArrayList<Integer>()); } final Bytes bytes = Bytes.of(boas.toByteArray()); final VisibilityBindingSetSerDe serde = new VisibilityBindingSetSerDe(); exception.expect(InvalidClassException.class); serde.deserialize(bytes); }
public VisibilityBindingSet deserialize(final Bytes bytes) throws Exception { requireNonNull(bytes); try (final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(new ByteArrayInputStream(bytes.toArray()))) { vois.accept( VisibilityBindingSet.class, java.lang.Byte.class, java.lang.Double.class, java.lang.Float.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Number.class, java.lang.Short.class, java.math.BigDecimal.class, java.math.BigInteger.class, java.util.LinkedHashMap.class, java.util.HashMap.class, org.apache.rya.api.model.BindingSetDecorator.class, org.eclipse.rdf4j.query.impl.SimpleBinding.class, org.eclipse.rdf4j.model.impl.SimpleIRI.class, org.eclipse.rdf4j.model.impl.SimpleLiteral.class, org.eclipse.rdf4j.model.impl.IntegerLiteral.class, org.eclipse.rdf4j.model.impl.DecimalLiteral.class, org.eclipse.rdf4j.model.impl.NumericLiteral.class, org.eclipse.rdf4j.query.AbstractBindingSet.class, org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet.class, org.eclipse.rdf4j.query.impl.MapBindingSet.class ); vois.accept("[B"); final Object o = vois.readObject(); if(o instanceof VisibilityBindingSet) { return (VisibilityBindingSet) o; } else { throw new Exception("Deserialized Object is not a VisibilityBindingSet. Was: " + o.getClass()); } } }
VisibilityBindingSetSerDe { public VisibilityBindingSet deserialize(final Bytes bytes) throws Exception { requireNonNull(bytes); try (final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(new ByteArrayInputStream(bytes.toArray()))) { vois.accept( VisibilityBindingSet.class, java.lang.Byte.class, java.lang.Double.class, java.lang.Float.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Number.class, java.lang.Short.class, java.math.BigDecimal.class, java.math.BigInteger.class, java.util.LinkedHashMap.class, java.util.HashMap.class, org.apache.rya.api.model.BindingSetDecorator.class, org.eclipse.rdf4j.query.impl.SimpleBinding.class, org.eclipse.rdf4j.model.impl.SimpleIRI.class, org.eclipse.rdf4j.model.impl.SimpleLiteral.class, org.eclipse.rdf4j.model.impl.IntegerLiteral.class, org.eclipse.rdf4j.model.impl.DecimalLiteral.class, org.eclipse.rdf4j.model.impl.NumericLiteral.class, org.eclipse.rdf4j.query.AbstractBindingSet.class, org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet.class, org.eclipse.rdf4j.query.impl.MapBindingSet.class ); vois.accept("[B"); final Object o = vois.readObject(); if(o instanceof VisibilityBindingSet) { return (VisibilityBindingSet) o; } else { throw new Exception("Deserialized Object is not a VisibilityBindingSet. Was: " + o.getClass()); } } } }
VisibilityBindingSetSerDe { public VisibilityBindingSet deserialize(final Bytes bytes) throws Exception { requireNonNull(bytes); try (final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(new ByteArrayInputStream(bytes.toArray()))) { vois.accept( VisibilityBindingSet.class, java.lang.Byte.class, java.lang.Double.class, java.lang.Float.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Number.class, java.lang.Short.class, java.math.BigDecimal.class, java.math.BigInteger.class, java.util.LinkedHashMap.class, java.util.HashMap.class, org.apache.rya.api.model.BindingSetDecorator.class, org.eclipse.rdf4j.query.impl.SimpleBinding.class, org.eclipse.rdf4j.model.impl.SimpleIRI.class, org.eclipse.rdf4j.model.impl.SimpleLiteral.class, org.eclipse.rdf4j.model.impl.IntegerLiteral.class, org.eclipse.rdf4j.model.impl.DecimalLiteral.class, org.eclipse.rdf4j.model.impl.NumericLiteral.class, org.eclipse.rdf4j.query.AbstractBindingSet.class, org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet.class, org.eclipse.rdf4j.query.impl.MapBindingSet.class ); vois.accept("[B"); final Object o = vois.readObject(); if(o instanceof VisibilityBindingSet) { return (VisibilityBindingSet) o; } else { throw new Exception("Deserialized Object is not a VisibilityBindingSet. Was: " + o.getClass()); } } }  }
VisibilityBindingSetSerDe { public VisibilityBindingSet deserialize(final Bytes bytes) throws Exception { requireNonNull(bytes); try (final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(new ByteArrayInputStream(bytes.toArray()))) { vois.accept( VisibilityBindingSet.class, java.lang.Byte.class, java.lang.Double.class, java.lang.Float.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Number.class, java.lang.Short.class, java.math.BigDecimal.class, java.math.BigInteger.class, java.util.LinkedHashMap.class, java.util.HashMap.class, org.apache.rya.api.model.BindingSetDecorator.class, org.eclipse.rdf4j.query.impl.SimpleBinding.class, org.eclipse.rdf4j.model.impl.SimpleIRI.class, org.eclipse.rdf4j.model.impl.SimpleLiteral.class, org.eclipse.rdf4j.model.impl.IntegerLiteral.class, org.eclipse.rdf4j.model.impl.DecimalLiteral.class, org.eclipse.rdf4j.model.impl.NumericLiteral.class, org.eclipse.rdf4j.query.AbstractBindingSet.class, org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet.class, org.eclipse.rdf4j.query.impl.MapBindingSet.class ); vois.accept("[B"); final Object o = vois.readObject(); if(o instanceof VisibilityBindingSet) { return (VisibilityBindingSet) o; } else { throw new Exception("Deserialized Object is not a VisibilityBindingSet. Was: " + o.getClass()); } } }  Bytes serialize(final VisibilityBindingSet bindingSet); VisibilityBindingSet deserialize(final Bytes bytes); }
VisibilityBindingSetSerDe { public VisibilityBindingSet deserialize(final Bytes bytes) throws Exception { requireNonNull(bytes); try (final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(new ByteArrayInputStream(bytes.toArray()))) { vois.accept( VisibilityBindingSet.class, java.lang.Byte.class, java.lang.Double.class, java.lang.Float.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Number.class, java.lang.Short.class, java.math.BigDecimal.class, java.math.BigInteger.class, java.util.LinkedHashMap.class, java.util.HashMap.class, org.apache.rya.api.model.BindingSetDecorator.class, org.eclipse.rdf4j.query.impl.SimpleBinding.class, org.eclipse.rdf4j.model.impl.SimpleIRI.class, org.eclipse.rdf4j.model.impl.SimpleLiteral.class, org.eclipse.rdf4j.model.impl.IntegerLiteral.class, org.eclipse.rdf4j.model.impl.DecimalLiteral.class, org.eclipse.rdf4j.model.impl.NumericLiteral.class, org.eclipse.rdf4j.query.AbstractBindingSet.class, org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet.class, org.eclipse.rdf4j.query.impl.MapBindingSet.class ); vois.accept("[B"); final Object o = vois.readObject(); if(o instanceof VisibilityBindingSet) { return (VisibilityBindingSet) o; } else { throw new Exception("Deserialized Object is not a VisibilityBindingSet. Was: " + o.getClass()); } } }  Bytes serialize(final VisibilityBindingSet bindingSet); VisibilityBindingSet deserialize(final Bytes bytes);  }