/** * De-serializes the given {@code input} according to the writer schema {@code WS}. * * @param input input payload to be de-serialized * @return O the de-serialized output * @throws SerDesException */ default O deserialize(I input) throws SerDesException { return deserialize(input, null); }
/** * De-serializes the given {@code input} according to the writer schema {@code WS}. * * @param input input payload to be de-serialized * @return O the de-serialized output * @throws SerDesException */ default O deserialize(I input) throws SerDesException { return deserialize(input, null); }
public void runCustomSerDesApi() throws Exception { // upload jar file String serdesJarName = "/serdes-examples.jar"; InputStream serdesJarInputStream = SampleSchemaRegistryClientApp.class.getResourceAsStream(serdesJarName); if (serdesJarInputStream == null) { throw new RuntimeException("Jar " + serdesJarName + " could not be loaded"); } String fileId = schemaRegistryClient.uploadFile(serdesJarInputStream); SchemaMetadata schemaMetadata = createSchemaMetadata("serdes-device-" + System.currentTimeMillis()); SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaMetadata, new SchemaVersion(getSchema("/device.avsc"), "Initial version of the schema")); // register serializer/deserializer Long serDesId = registerSimpleSerDes(fileId); // map serializer and deserializer with schemakey // for each schema, one serializer/deserializer is sufficient unless someone want to maintain multiple implementations of serializers/deserializers String schemaName = schemaMetadata.getName(); schemaRegistryClient.mapSchemaWithSerDes(schemaName, serDesId); SnapshotSerializer<Object, byte[], SchemaMetadata> snapshotSerializer = getSnapshotSerializer(schemaMetadata); String payload = "Random text: " + new Random().nextLong(); byte[] serializedBytes = snapshotSerializer.serialize(payload, schemaMetadata); SnapshotDeserializer<byte[], Object, Integer> snapshotdeserializer = getSnapshotDeserializer(schemaMetadata); Object deserializedObject = snapshotdeserializer.deserialize(serializedBytes, null); LOG.info("Given payload and deserialized object are equal: " + payload.equals(deserializedObject)); }