Search in sources :

Example 26 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class ElementCloner method cloneElement.

/**
 * Clone an {@link Element}, based on a target {@link Schema}.
 *
 * @param element the element to clone
 * @param schema the schema
 * @return the cloned element
 */
public Element cloneElement(final Element element, final Schema schema) {
    try {
        final Element clone = element.emptyClone();
        final SchemaElementDefinition sed = schema.getElement(clone.getGroup());
        for (final String propertyName : element.getProperties().keySet()) {
            final Object property = element.getProperty(propertyName);
            if (null == sed.getPropertyTypeDef(propertyName) || null == sed.getPropertyTypeDef(propertyName).getSerialiser()) {
                // This can happen if transient properties are derived - they will not have serialisers.
                LOGGER.warn("Can't find Serialisation for {}, returning uncloned property", propertyName);
                clone.putProperty(propertyName, property);
            } else if (null != property) {
                final Serialiser serialiser = sed.getPropertyTypeDef(propertyName).getSerialiser();
                clone.putProperty(propertyName, serialiser.deserialise(serialiser.serialise(property)));
            } else {
                clone.putProperty(propertyName, null);
            }
        }
        return clone;
    } catch (final SerialisationException e) {
        throw new RuntimeException("SerialisationException converting elements", e);
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) Element(uk.gov.gchq.gaffer.data.element.Element) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 27 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project gaffer-doc by gchq.

the class PropertiesWalkthrough method listOtherSerialisers.

protected boolean listOtherSerialisers(final Class<?> clazz) {
    final List<String> serialiserClasses = new ArrayList<>();
    for (final Serialiser serialise : SERIALISERS) {
        if (serialise.canHandle(clazz)) {
            serialiserClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(serialise.getClass(), false, 3));
        }
    }
    if (!serialiserClasses.isEmpty()) {
        print(SERIALISERS_KEY, "\nOther Serialisers:");
        print(SERIALISERS_KEY, "\n- " + StringUtils.join(serialiserClasses, "\n- "));
    }
    return !serialiserClasses.isEmpty();
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) AvroSerialiser(uk.gov.gchq.gaffer.serialisation.AvroSerialiser) ArrayList(java.util.ArrayList)

Example 28 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project gaffer-doc by gchq.

the class PropertiesWalkthrough method getSerialisers.

private static List<Serialiser> getSerialisers() {
    final List<Serialiser> serialisers = getSubClassInstances(Serialiser.class);
    serialisers.removeIf(c -> {
        boolean contains = false;
        for (final ToBytesSerialiser serialiser : TO_BYTES_SERIALISERS) {
            if (serialiser.getClass().equals(c.getClass())) {
                contains = true;
                break;
            }
        }
        return contains;
    });
    return serialisers;
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) AvroSerialiser(uk.gov.gchq.gaffer.serialisation.AvroSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)

Aggregations

Serialiser (uk.gov.gchq.gaffer.serialisation.Serialiser)28 Test (org.junit.jupiter.api.Test)18 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)18 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)16 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)10 BooleanSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser)8 OrderedIntegerSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser)8 RawDateSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser)8 RawDoubleSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser)8 RawFloatSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser)8 StringToStringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser)6 MapSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser)5 RawLongSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser)5 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 ArrayList (java.util.ArrayList)3 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)3 AvroSerialiser (uk.gov.gchq.gaffer.serialisation.AvroSerialiser)3 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2