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
Base class for JSON message converters; on the consumer side, it can
 handle 
byte[], Bytes and String record values.
 On the producer side, select a subclass that matches the corresponding
 Kafka Serializer.- Since:
- 2.3
- Author:
- Gary Russell
- 
Field SummaryFields inherited from class org.springframework.kafka.support.converter.MessagingMessageConverterlogger
- 
Constructor SummaryConstructorsConstructorDescriptionJsonMessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected ObjectconvertPayload(Message<?> message) Subclasses can convert the payload; by default, it's sent unchanged to Kafka.protected ObjectextractAndConvertValue(org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record, Type type) Subclasses can convert the value; by default, it's returned as provided by Kafka unless there is aSmartMessageConverterthat can convert it.protected com.fasterxml.jackson.databind.ObjectMapperReturn the object mapper.protected org.apache.kafka.common.header.HeadersinitialRecordHeaders(Message<?> message) Subclasses can populate additional headers before they are mapped.voidsetTypeMapper(Jackson2JavaTypeMapper typeMapper) Set a customized type mapper.Methods inherited from class org.springframework.kafka.support.converter.MessagingMessageConverterfromMessage, getMessagingConverter, setGenerateMessageId, setGenerateTimestamp, setHeaderMapper, setMessagingConverter, setRawRecordHeader, toMessageMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.kafka.support.converter.MessageConvertercommonHeaders
- 
Constructor Details- 
JsonMessageConverterpublic JsonMessageConverter()
- 
JsonMessageConverterpublic JsonMessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper) 
 
- 
- 
Method Details- 
getTypeMapper
- 
setTypeMapperSet a customized type mapper.- Parameters:
- typeMapper- the type mapper.
 
- 
getObjectMapperprotected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Return the object mapper.- Returns:
- the mapper.
 
- 
initialRecordHeadersDescription copied from class:MessagingMessageConverterSubclasses can populate additional headers before they are mapped.- Overrides:
- initialRecordHeadersin class- MessagingMessageConverter
- Parameters:
- message- the message.
- Returns:
- the headers
 
- 
convertPayloadDescription copied from class:MessagingMessageConverterSubclasses can convert the payload; by default, it's sent unchanged to Kafka.- Overrides:
- convertPayloadin class- MessagingMessageConverter
- Parameters:
- message- the message.
- Returns:
- the payload.
 
- 
extractAndConvertValueprotected Object extractAndConvertValue(org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> record, Type type) Description copied from class:MessagingMessageConverterSubclasses can convert the value; by default, it's returned as provided by Kafka unless there is aSmartMessageConverterthat can convert it.- Overrides:
- extractAndConvertValuein class- MessagingMessageConverter
- Parameters:
- record- the record.
- type- the required type.
- Returns:
- the value.
 
 
-