Class JsonMessageConverter
- java.lang.Object
-
- org.springframework.kafka.support.converter.MessagingMessageConverter
-
- org.springframework.kafka.support.converter.JsonMessageConverter
-
- All Implemented Interfaces:
MessageConverter
,RecordMessageConverter
- Direct Known Subclasses:
ByteArrayJsonMessageConverter
,BytesJsonMessageConverter
,StringJsonMessageConverter
public class JsonMessageConverter extends MessagingMessageConverter
Base class for JSON message converters; on the consumer side, it can handlebyte[]
,Bytes
andString
record values. On the producer side, select a subclass that matches the corresponding Kafka Serializer.- Since:
- 2.3
- Author:
- Gary Russell
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.support.converter.MessagingMessageConverter
logger
-
-
Constructor Summary
Constructors Constructor Description JsonMessageConverter()
JsonMessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
convertPayload(org.springframework.messaging.Message<?> message)
Subclasses can convert the payload; by default, it's sent unchanged to Kafka.protected java.lang.Object
extractAndConvertValue(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, java.lang.reflect.Type type)
Subclasses can convert the value; by default, it's returned as provided by Kafka unless there is aSmartMessageConverter
that can convert it.protected com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
Return the object mapper.Jackson2JavaTypeMapper
getTypeMapper()
protected org.apache.kafka.common.header.Headers
initialRecordHeaders(org.springframework.messaging.Message<?> message)
Subclasses can populate additional headers before they are mapped.void
setTypeMapper(Jackson2JavaTypeMapper typeMapper)
Set a customized type mapper.-
Methods inherited from class org.springframework.kafka.support.converter.MessagingMessageConverter
fromMessage, getMessagingConverter, setGenerateMessageId, setGenerateTimestamp, setHeaderMapper, setMessagingConverter, setRawRecordHeader, toMessage
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.kafka.support.converter.MessageConverter
commonHeaders
-
-
-
-
Method Detail
-
getTypeMapper
public Jackson2JavaTypeMapper getTypeMapper()
-
setTypeMapper
public void setTypeMapper(Jackson2JavaTypeMapper typeMapper)
Set a customized type mapper.- Parameters:
typeMapper
- the type mapper.
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Return the object mapper.- Returns:
- the mapper.
-
initialRecordHeaders
protected org.apache.kafka.common.header.Headers initialRecordHeaders(org.springframework.messaging.Message<?> message)
Description copied from class:MessagingMessageConverter
Subclasses can populate additional headers before they are mapped.- Overrides:
initialRecordHeaders
in classMessagingMessageConverter
- Parameters:
message
- the message.- Returns:
- the headers
-
convertPayload
protected java.lang.Object convertPayload(org.springframework.messaging.Message<?> message)
Description copied from class:MessagingMessageConverter
Subclasses can convert the payload; by default, it's sent unchanged to Kafka.- Overrides:
convertPayload
in classMessagingMessageConverter
- Parameters:
message
- the message.- Returns:
- the payload.
-
extractAndConvertValue
protected java.lang.Object extractAndConvertValue(org.apache.kafka.clients.consumer.ConsumerRecord<?,?> record, java.lang.reflect.Type type)
Description copied from class:MessagingMessageConverter
Subclasses can convert the value; by default, it's returned as provided by Kafka unless there is aSmartMessageConverter
that can convert it.- Overrides:
extractAndConvertValue
in classMessagingMessageConverter
- Parameters:
record
- the record.type
- the required type.- Returns:
- the value.
-
-