简体   繁体   English

如何在序列化程序 class 中调用默认方法

[英]How to invoke default method in serializer class

I have been trying to write a custom Serializer by extending the apache Serialzier class.我一直在尝试通过扩展 apache Serialzier class 来编写自定义序列化程序。

the serializer method contains to methods of importance to me序列化器方法包含对我很重要的方法

byte[] serialize(String topic, T data); 
default byte[] serialize(String topic, Headers headers, T data) {
       return serialize(topic, data);
   }

but whenever I write a custom implemetation for the serialzier it calls the overrided method但是每当我为 serialzier 编写自定义实现时,它都会调用覆盖的方法

byte[] serialize(String topic, T data); 

Iam passing this class to kafka producer for serializer and hence I can't invoke these methods directly and the framework by default access the method.我将这个 class 传递给序列化程序的 kafka 生产者,因此我不能直接调用这些方法,默认情况下框架会访问该方法。

But I want to invoke the default method instead of the overrided method.但我想调用默认方法而不是重写方法。 It is not possible to call the default method from other method since the headers are expected.由于需要标头,因此无法从其他方法调用默认方法。 Is there anyway to invoke default method instead of the overriden one while passing the serialzier for producer/consumer configuration?在传递生产者/消费者配置的序列化器时,是否有调用默认方法而不是覆盖的方法?

The fact that you've overwritten the method definition in the interface implementation means that's what's going to be called您已经覆盖了接口实现中的方法定义这一事实意味着这就是将要调用的内容

It is not possible to call the default method from other method since the headers are expected由于需要标头,因此无法从其他方法调用默认方法

You should be able to pass null as the headers parameter您应该能够将 null 作为 headers 参数传递

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM