AbstractCoreKeyAccumuloElementConverter implements AccumuloElementConverter { protected void serialiseSizeAndPropertyValue(final String propertyName, final SchemaElementDefinition elementDefinition, final Properties properties, final ByteArrayOutputStream stream) { try { final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName); final ToBytesSerialiser serialiser = (null == typeDefinition) ? null : (ToBytesSerialiser) typeDefinition.getSerialiser(); byte[] bytes; if (null == serialiser) { bytes = AccumuloStoreConstants.EMPTY_BYTES; } else { Object value = properties.get(propertyName); bytes = (null == value) ? serialiser.serialiseNull() : serialiser.serialise(value); } writeBytes(bytes, stream); } catch (final IOException e) { throw new AccumuloElementConversionException("Failed to write serialised property to ByteArrayOutputStream" + propertyName, e); } } AbstractCoreKeyAccumuloElementConverter(final Schema schema); @Override ElementId getElementId(final Key key, final boolean includeMatchedVertex); @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge") @Override Pair<Key, Key> getKeysFromElement(final Element element); @Override Pair<Key, Key> getKeysFromEdge(final Edge edge); @Override Key getKeyFromEntity(final Entity entity); @SuppressWarnings("Convert2streamapi") @Override Value getValueFromProperties(final String group, final Properties properties); @Override Value getValueFromElement(final Element element); @Override Properties getPropertiesFromValue(final String group, final Value value); @Override Element getElementFromKey(final Key key, final boolean includeMatchedVertex); @Override Element getFullElement(final Key key, final Value value, final boolean includeMatchedVertex); @Override Pair<byte[], byte[]> getRowKeysFromElement(final Element element); @Override byte[] buildColumnFamily(final String group); @Override String getGroupFromColumnFamily(final byte[] columnFamily); @Override byte[] buildColumnVisibility(final String group, final Properties properties); @Override Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility); @Override byte[] buildColumnQualifier(final String group, final Properties properties); @Override Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes); @Override BytesAndRange getPropertiesAsBytesFromColumnQualifier(final String group, final byte[] bytes, final int numProps); @Override long buildTimestamp(final String group, final Properties properties); @Override Properties getPropertiesFromTimestamp(final String group, final long timestamp); @Override byte[] serialiseVertex(final Object vertex);  }
@Test public void shouldReturnOverriddenSerialiseNull() throws Exception { ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] expected = Bytes.concat(new byte[]{5}, "Empty".getBytes()); Schema testSchema = new Schema.Builder() .edge("group1", new SchemaEdgeDefinition.Builder() .source("string") .destination("string") .directed("true") .property("prop1", "string") .property("invalidProp", "unusualSerialiser") .build()) .type("string", new TypeDefinition.Builder() .clazz(String.class) .serialiser(new StringSerialiser()) .build()) .type("true", Boolean.class) .type("unusualSerialiser", new TypeDefinition.Builder() .clazz(String.class) .serialiser(new UnusualTestSerialiser()) .build()) .build(); createConverter(testSchema).serialiseSizeAndPropertyValue("invalidProp", testSchema.getElement("group1"), new Properties(), stream); assertArrayEquals(expected, stream.toByteArray()); }