[ 
https://issues.apache.org/jira/browse/KAFKA-6864?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16479145#comment-16479145
 ] 

Mathias Kub commented on KAFKA-6864:
------------------------------------

[~mjsax] Yes I do, but my explanation was not enough.

The serializer looks like
{code:java}
override def serialize(topic: String, data: StateValue[T]): Array[Byte] = {
  data match {
    case NewState(value) =>
      codec(value).getBytes(charset)
    case DeleteState =>
      null
  }
}{code}
and the deserializer looks like
{code:java}
  override def deserialize(topic: String, data: Array[Byte]): StateValue[T] = {
    if (data != null) {
      codec.invert(new String(data, charset)) match {
        case Success(value) =>
          NewState(value)
        case Failure(exception) =>
          throw new SerializationException(s"Error when deserializing byte[] to 
record", exception)
      }
    } else {
      DeleteState
    }
  }
{code}

The state classes are
{code}
sealed trait StateValue[+V]
case class NewState[V](value: V) extends StateValue[V]
case object DeleteState extends StateValue[Nothing]
{code}

Hope this helps.

[~guozhang] Thanks.

> null is not passed to keyDeserialzer and valueDeserializer in Fetcher
> ---------------------------------------------------------------------
>
>                 Key: KAFKA-6864
>                 URL: https://issues.apache.org/jira/browse/KAFKA-6864
>             Project: Kafka
>          Issue Type: Bug
>          Components: consumer
>    Affects Versions: 1.1.0
>            Reporter: Mathias Kub
>            Priority: Major
>
> Hi,
> currently null values are not passed to the keyDeserializer and 
> valueDeserializer in the Fetcher class. This prevents custom deserialization 
> of null values.
> The Deserializer JavaDoc says
> {code:java}
> /**
> * Deserialize a record value from a byte array into a value or object.
> * @param topic topic associated with the data
> * @param data serialized bytes; may be null; implementations are recommended 
> to handle null by returning a value or null rather than throwing an exception.
> * @return deserialized typed data; may be null
> */
> T deserialize(String topic, byte[] data);{code}
> so as for my understanding, null values should be passed to it.
>  
> Thanks,
> Mathias



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to