@Override public <T> T getDefaultSerializer(String type) throws SerDesException { Collection<SchemaProviderInfo> supportedSchemaProviders = getSupportedSchemaProviders(); for (SchemaProviderInfo schemaProvider : supportedSchemaProviders) { if (schemaProvider.getType().equals(type)) { try { return (T) Class.forName(schemaProvider.getDefaultSerializerClassName()).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new SerDesException(e); } } } throw new IllegalArgumentException("No schema provider registered for the given type " + type); }
@Override public <T> T getDefaultDeserializer(String type) throws SerDesException { Collection<SchemaProviderInfo> supportedSchemaProviders = getSupportedSchemaProviders(); for (SchemaProviderInfo schemaProvider : supportedSchemaProviders) { if (schemaProvider.getType().equals(type)) { try { return (T) Class.forName(schemaProvider.getDefaultDeserializerClassName()).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new SerDesException(e); } } } throw new IllegalArgumentException("No schema provider registered for the given type " + type); }
new ClassLoaderAwareInvocationHandler(classLoader, t)); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new SerDesException(e);
@Override public void mapSchemaWithSerDes(String schemaName, Long serDesId) { SerDesInfo serDesInfo = getSerDes(serDesId); if (serDesInfo == null) { throw new SerDesException("Serializer with given ID " + serDesId + " does not exist"); } SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName); SchemaSerDesMapping schemaSerDesMapping = new SchemaSerDesMapping(schemaMetadataInfo.getId(), serDesId); storageManager.add(schemaSerDesMapping); }
@Override protected MessageContext doSerialize(Object input, SchemaIdVersion schemaIdVersion) throws SerDesException { Map<String, Object> headers = new HashMap<>(); headers.put("protocol.id", getProtocolId()); headers.put("schema.metadata.id", schemaIdVersion.getSchemaMetadataId()); headers.put("schema.version", schemaIdVersion.getVersion()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(baos)) { serializePayload(bufferedOutputStream, input); } catch (IOException e) { throw new SerDesException(e); } ByteArrayInputStream payload = new ByteArrayInputStream(baos.toByteArray()); return new MessageContext(headers, payload); } }