@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return converter.canConvert(byte[].class, expectedRepresentation); }
/** * Converts the given object into another. * * @param original the value to convert * @param targetType The type of data to convert to * @param <T> the target data type * @return the converted value */ default <T> T convert(Object original, Class<T> targetType) { return convert(original, original.getClass(), targetType); }
@Override public <D> SerializedObject<D> getData(Class<D> requiredType) { return converter.convert(getData(), requiredType); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return converter.canConvert(byte[].class, expectedRepresentation); }
@Override @SuppressWarnings("unchecked") public <D> SerializedObject<D> getData(Class<D> requiredType) { return serializer.getConverter().convert(data, requiredType); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return JsonNode.class.equals(expectedRepresentation) || String.class.equals(expectedRepresentation) || converter.canConvert(byte[].class, expectedRepresentation); }
/** * Convert the given {@code source}, of type {@code sourceType} to the given {@code targetType}. * * @param <S> The type of data that needs to be converted * @param <T> The target type of the conversion * @param source The object to convert * @param sourceType The source type of the conversion * @param targetType The target type of the conversion * @return The converted object */ protected <S, T> T convert(S source, Class<S> sourceType, Class<T> targetType) { return getConverter().convert(source, sourceType, targetType); }
/** * Indicates whether the given {@code desiredFormat} is supported as a representation for this type. More * specifically, it will consult the serializer that returned this instance whether it has a converter to convert * the serialized object's data to the desired type * * @param desiredFormat the format in which the serialized object is desired * @param <T> the format in which the serialized object is desired * @return {@code true} if the format is supported, otherwise {@code false} */ public <T> boolean supportsFormat(Class<T> desiredFormat) { return serializer.getConverter().canConvert(serializedObject.getContentType(), desiredFormat); }
/** * Returns the data contained in the serialized object in the given {@code desiredFormat}, if supported. If the * desired format is unsupported, an exception is thrown, depending on the serializer. * <p> * To verify whether a format is supported, use {@link #supportsFormat(Class)}. * * @param desiredFormat the format in which the data is desired * @param <T> the format in which the data is desired * @return the data in the desired format */ public <T> T readData(Class<T> desiredFormat) { return serializer.getConverter().convert(serializedObject, desiredFormat).getData(); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return converter.canConvert(byte[].class, expectedRepresentation); }
@SuppressWarnings({"NonSerializableObjectPassedToObjectStream", "ThrowFromFinallyBlock"}) @Override public <T> SerializedObject<T> serialize(Object instance, Class<T> expectedType) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(baos); try { oos.writeObject(instance); } finally { oos.flush(); } } catch (IOException e) { throw new SerializationException("An exception occurred writing serialized data to the output stream", e); } T converted = converter.convert(baos.toByteArray(), expectedType); return new SimpleSerializedObject<>(converted, expectedType, getSerializedType(instance)); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return converter.canConvert(byte[].class, expectedRepresentation); }
@SuppressWarnings("unchecked") public <T> SerializedObject<T> serializeMetaData(Serializer serializer, Class<T> expectedRepresentation) { synchronized (metaDataGuard) { SerializedObject existingForm = serializedMetaData.get(serializer); if (existingForm == null) { SerializedObject<T> serialized = serializer.serialize(message.getMetaData(), expectedRepresentation); serializedMetaData.put(serializer, serialized); return serialized; } else { return serializer.getConverter().convert(existingForm, expectedRepresentation); } } } }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return converter.canConvert(byte[].class, expectedRepresentation); }
@Override @SuppressWarnings("unchecked") public SerializedObject<T> getData() { SerializedObject<?> serializedInput = converter.convert(source.getData(), requiredType); return new SimpleSerializedObject<>(upcastFunction.apply((T) serializedInput.getData()), requiredType, getType()); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return converter.canConvert(byte[].class, expectedRepresentation); }
@SuppressWarnings("unchecked") @Override public <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) { if (serializer.equals(payload.getSerializer())) { return serializer.getConverter().convert(payload.getSerializedObject(), expectedRepresentation); } return serializer.serialize(payload.getObject(), expectedRepresentation); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return JsonNode.class.equals(expectedRepresentation) || String.class.equals(expectedRepresentation) || converter.canConvert(byte[].class, expectedRepresentation); }
@SuppressWarnings("unchecked") @Override public <R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) { if (serializer.equals(metaData.getSerializer())) { return serializer.getConverter().convert(metaData.getSerializedObject(), expectedRepresentation); } return serializer.serialize(metaData.getObject(), expectedRepresentation); }
@Override public <T> boolean canSerializeTo(Class<T> expectedRepresentation) { return JsonNode.class.equals(expectedRepresentation) || String.class.equals(expectedRepresentation) || converter.canConvert(byte[].class, expectedRepresentation); }