You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/common/serialization/Deserializer.java
+52-20
Original file line number
Diff line number
Diff line change
@@ -25,39 +25,61 @@
25
25
26
26
/**
27
27
* An interface for converting bytes to objects.
28
-
*
29
28
* A class that implements this interface is expected to have a constructor with no parameters.
30
-
* <p>
31
-
* Implement {@link org.apache.kafka.common.ClusterResourceListener} to receive cluster metadata once it's available. Please see the class documentation for ClusterResourceListener for more information.
32
-
* Implement {@link org.apache.kafka.common.metrics.Monitorable} to enable the deserializer to register metrics. The following tags are automatically added to
33
-
* all metrics registered: <code>config</code> set to either <code>key.deserializer</code> or <code>value.deserializer</code>, and <code>class</code> set to the Deserializer class name.
29
+
*
30
+
* <p>This interface can be combined with {@link org.apache.kafka.common.ClusterResourceListener ClusterResourceListener}
31
+
* to receive cluster metadata once it's available, as well as {@link org.apache.kafka.common.metrics.Monitorable Monitorable}
32
+
* to enable the deserializer to register metrics. For the latter, the following tags are automatically added to
33
+
* all metrics registered: {@code config} set to either {@code key.deserializer} or {@code value.deserializer},
34
+
* and {@code class} set to the deserializer class name.
35
+
*
34
36
* @param <T> Type to be deserialized into.
35
37
*/
36
38
publicinterfaceDeserializer<T> extendsCloseable {
37
39
38
40
/**
39
41
* Configure this class.
40
-
* @param configs configs in key/value pairs
41
-
* @param isKey whether is for key or value
42
+
*
43
+
* @param configs
44
+
* configs in key/value pairs
45
+
* @param isKey
46
+
* whether the deserializer is used for the key or the value
* Deserialize a record value from a byte array into a value or object.
49
-
* @param topic topic associated with the data
50
-
* @param data serialized bytes; may be null; implementations are recommended to handle null by returning a value or null rather than throwing an exception.
51
-
* @return deserialized typed data; may be null
54
+
*
55
+
* <p>It is recommended to deserialize a {@code null} byte array to a {@code null} object.
56
+
*
57
+
* @param topic
58
+
* topic associated with the data
59
+
* @param data
60
+
* serialized bytes; may be {@code null}
61
+
*
62
+
* @return deserialized typed data; may be {@code null}
52
63
*/
53
64
Tdeserialize(Stringtopic, byte[] data);
54
65
55
66
/**
56
67
* Deserialize a record value from a byte array into a value or object.
57
-
* @param topic topic associated with the data
58
-
* @param headers headers associated with the record; may be empty.
59
-
* @param data serialized bytes; may be null; implementations are recommended to handle null by returning a value or null rather than throwing an exception.
60
-
* @return deserialized typed data; may be null
68
+
*
69
+
* <p>It is recommended to deserialize a {@code null} byte array to a {@code null} object.
70
+
*
71
+
* <p>Note that the passed in {@link Headers} may be empty, but never {@code null}.
72
+
* The implementation is allowed to modify the passed in headers, as a side effect of deserialization.
73
+
* It is considered best practice to not delete or modify existing headers, but rather only add new ones.
74
+
*
75
+
* @param topic
76
+
* topic associated with the data
77
+
* @param headers
78
+
* headers associated with the record
79
+
* @param data
80
+
* serialized bytes; may be {@code null}
81
+
*
82
+
* @return deserialized typed data; may be {@code null}
* <p>Similarly, if this method is overridden, the implementation cannot make any assumptions about the
74
96
* passed in {@link ByteBuffer} either.
75
97
*
76
-
* @param topic topic associated with the data
77
-
* @param headers headers associated with the record; may be empty.
78
-
* @param data serialized ByteBuffer; may be null; implementations are recommended to handle null by returning a value or null rather than throwing an exception.
79
-
* @return deserialized typed data; may be null
98
+
* <p>It is recommended to deserialize a {@code null} {@link ByteBuffer} to a {@code null} object.
99
+
*
100
+
* <p>Note that the passed in {@link Headers} may be empty, but never {@code null}.
101
+
* The implementation is allowed to modify the passed in headers, as a side effect of deserialization.
102
+
* It is considered best practice to not delete or modify existing headers, but rather only add new ones.
103
+
*
104
+
* @param topic
105
+
* topic associated with the data
106
+
* @param headers
107
+
* headers associated with the record
108
+
* @param data
109
+
* serialized ByteBuffer; may be {@code null}
110
+
*
111
+
* @return deserialized typed data; may be {@code null}
Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/common/serialization/Serializer.java
+36-16
Original file line number
Diff line number
Diff line change
@@ -23,20 +23,25 @@
23
23
24
24
/**
25
25
* An interface for converting objects to bytes.
26
-
*
27
26
* A class that implements this interface is expected to have a constructor with no parameter.
28
-
* <p>
29
-
* Implement {@link org.apache.kafka.common.ClusterResourceListener} to receive cluster metadata once it's available. Please see the class documentation for ClusterResourceListener for more information.
30
-
* Implement {@link org.apache.kafka.common.metrics.Monitorable} to enable the serializer to register metrics. The following tags ae automatically added to
31
-
* all metrics registered: <code>config</code> set to either <code>key.serializer</code> or <code>value.serializer</code>, and <code>class</code> set to the Serializer class name.
27
+
*
28
+
* <p>This interface can be combined with {@link org.apache.kafka.common.ClusterResourceListener ClusterResourceListener}
29
+
* to receive cluster metadata once it's available, as well as {@link org.apache.kafka.common.metrics.Monitorable Monitorable}
30
+
* to enable the serializer to register metrics. For the latter, the following tags are automatically added to all
31
+
* metrics registered: {@code config} set to either {@code key.serializer} or {@code value.serializer},
32
+
* and {@code class} set to the serializer class name.
33
+
*
32
34
* @param <T> Type to be serialized from.
33
35
*/
34
36
publicinterfaceSerializer<T> extendsCloseable {
35
37
36
38
/**
37
39
* Configure this class.
38
-
* @param configs configs in key/value pairs
39
-
* @param isKey whether is for key or value
40
+
*
41
+
* @param configs
42
+
* configs in key/value pairs
43
+
* @param isKey
44
+
* whether the serializer is used for the key or the value
0 commit comments