Class JsonPulsarHeaderMapper
java.lang.Object
org.springframework.pulsar.support.header.AbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,JsonPulsarHeaderMapper.ToSpringHeadersContext>
org.springframework.pulsar.support.header.JsonPulsarHeaderMapper
- All Implemented Interfaces:
PulsarHeaderMapper
public class JsonPulsarHeaderMapper
extends AbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,JsonPulsarHeaderMapper.ToSpringHeadersContext>
A
PulsarHeaderMapper
implementation that writes headers as JSON.
Allows user to constrain which classes are "trusted"
for deserialization as
well as configure a list of classes to serialize with a simple "toString"
.
- Author:
- Chris Bono
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static final record
Represents a header that could not be decoded due to an untrusted type.static final record
Context used forAbstractPulsarHeaderMapper.toPulsarHeaders(org.springframework.messaging.MessageHeaders)
(outbound) that includes the cumulative map of header name to classname for headers that are serialized with JSON.static final record
Context used forAbstractPulsarHeaderMapper.toSpringHeaders(org.apache.pulsar.client.api.Message<?>)
(inbound) that includes the cumulative map of header name to classname for headers in the incoming message that were serialized with JSON. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Header name for java types of other headers.Fields inherited from class org.springframework.pulsar.support.header.AbstractPulsarHeaderMapper
logger
-
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Construct a builder instance that can be used to construct aJsonPulsarHeaderMapper
.protected com.fasterxml.jackson.databind.ObjectMapper
protected boolean
matchesForInbound
(String header) Determine if a header name matches any of the currently configured list of inbound matchers.protected void
toPulsarHeadersOnCompleted
(MessageHeaders springHeaders, Map<String, String> pulsarHeaders, JsonPulsarHeaderMapper.ToPulsarHeadersContext context) Called at the end of a successfulAbstractPulsarHeaderMapper.toSpringHeaders(org.apache.pulsar.client.api.Message<?>)
invocation.toPulsarHeadersOnStarted
(MessageHeaders springHeaders) Called at the beginning of everyAbstractPulsarHeaderMapper.toPulsarHeaders(org.springframework.messaging.MessageHeaders)
invocation and the returned value is passed into eachAbstractPulsarHeaderMapper.toPulsarHeaderValue(java.lang.String, java.lang.Object, ToPulsarHeadersContextType)
invocation as well as the finalAbstractPulsarHeaderMapper.toPulsarHeadersOnCompleted(org.springframework.messaging.MessageHeaders, java.util.Map<java.lang.String, java.lang.String>, ToPulsarHeadersContextType)
.protected String
toPulsarHeaderValue
(String name, Object rawValue, JsonPulsarHeaderMapper.ToPulsarHeadersContext context) Determine the Pulsar header value to use for a Spring Messaging header.toSpringHeadersOnStarted
(org.apache.pulsar.client.api.Message<?> pulsarMessage) Called at the beginning of everyAbstractPulsarHeaderMapper.toSpringHeaders(org.apache.pulsar.client.api.Message<?>)
invocation and the returned value is passed into eachAbstractPulsarHeaderMapper.toSpringHeaderValue(java.lang.String, java.lang.String, ToSpringHeadersContextType)
invocation as well as the finalAbstractPulsarHeaderMapper.toSpringHeadersOnCompleted(org.apache.pulsar.client.api.Message<?>, org.springframework.messaging.MessageHeaders, ToSpringHeadersContextType)
.protected Object
toSpringHeaderValue
(String name, String value, JsonPulsarHeaderMapper.ToSpringHeadersContext context) Determine the Spring Messaging header value to use for a Pulsar header.protected boolean
Methods inherited from class org.springframework.pulsar.support.header.AbstractPulsarHeaderMapper
matchesForOutbound, toPulsarHeaders, toSpringHeaders, toSpringHeadersOnCompleted
-
Field Details
-
JSON_TYPES
Header name for java types of other headers.- See Also:
-
-
Method Details
-
builder
Construct a builder instance that can be used to construct aJsonPulsarHeaderMapper
.- Returns:
- builder instance
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
getTrustedPackages
-
getToStringClasses
-
toPulsarHeadersOnStarted
protected JsonPulsarHeaderMapper.ToPulsarHeadersContext toPulsarHeadersOnStarted(MessageHeaders springHeaders) Description copied from class:AbstractPulsarHeaderMapper
Called at the beginning of everyAbstractPulsarHeaderMapper.toPulsarHeaders(org.springframework.messaging.MessageHeaders)
invocation and the returned value is passed into eachAbstractPulsarHeaderMapper.toPulsarHeaderValue(java.lang.String, java.lang.Object, ToPulsarHeadersContextType)
invocation as well as the finalAbstractPulsarHeaderMapper.toPulsarHeadersOnCompleted(org.springframework.messaging.MessageHeaders, java.util.Map<java.lang.String, java.lang.String>, ToPulsarHeadersContextType)
. Allows concrete implementations the ability to create an arbitrary context object and have it passed through the mapping process.- Overrides:
toPulsarHeadersOnStarted
in classAbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,
JsonPulsarHeaderMapper.ToSpringHeadersContext> - Parameters:
springHeaders
- the Spring Messaging headers that are being converted- Returns:
- optional context to pass through the mapping invocation
-
toPulsarHeaderValue
protected String toPulsarHeaderValue(String name, Object rawValue, JsonPulsarHeaderMapper.ToPulsarHeadersContext context) Description copied from class:AbstractPulsarHeaderMapper
Determine the Pulsar header value to use for a Spring Messaging header.- Specified by:
toPulsarHeaderValue
in classAbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,
JsonPulsarHeaderMapper.ToSpringHeadersContext> - Parameters:
name
- the Spring Messaging header namerawValue
- the Spring Messaging header valuecontext
- the optional context used for the mapping invocation- Returns:
- the Pulsar header value to use
-
toPulsarHeadersOnCompleted
protected void toPulsarHeadersOnCompleted(MessageHeaders springHeaders, Map<String, String> pulsarHeaders, JsonPulsarHeaderMapper.ToPulsarHeadersContext context) Description copied from class:AbstractPulsarHeaderMapper
Called at the end of a successfulAbstractPulsarHeaderMapper.toSpringHeaders(org.apache.pulsar.client.api.Message<?>)
invocation. Allows concrete implementations the ability to do final logic/cleanup.- Overrides:
toPulsarHeadersOnCompleted
in classAbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,
JsonPulsarHeaderMapper.ToSpringHeadersContext> - Parameters:
springHeaders
- the Spring Messaging headers that were mappedpulsarHeaders
- the resulting map of Pulsar message headerscontext
- the optional context used for the mapping invocation
-
matchesForInbound
Description copied from class:AbstractPulsarHeaderMapper
Determine if a header name matches any of the currently configured list of inbound matchers.- Overrides:
matchesForInbound
in classAbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,
JsonPulsarHeaderMapper.ToSpringHeadersContext> - Parameters:
header
- the name of the header to check- Returns:
- whether the header matches for inbound
-
toSpringHeadersOnStarted
@NonNull protected JsonPulsarHeaderMapper.ToSpringHeadersContext toSpringHeadersOnStarted(org.apache.pulsar.client.api.Message<?> pulsarMessage) Description copied from class:AbstractPulsarHeaderMapper
Called at the beginning of everyAbstractPulsarHeaderMapper.toSpringHeaders(org.apache.pulsar.client.api.Message<?>)
invocation and the returned value is passed into eachAbstractPulsarHeaderMapper.toSpringHeaderValue(java.lang.String, java.lang.String, ToSpringHeadersContextType)
invocation as well as the finalAbstractPulsarHeaderMapper.toSpringHeadersOnCompleted(org.apache.pulsar.client.api.Message<?>, org.springframework.messaging.MessageHeaders, ToSpringHeadersContextType)
. Allows concrete implementations the ability to create an arbitrary context object and have it passed through the mapping process.- Overrides:
toSpringHeadersOnStarted
in classAbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,
JsonPulsarHeaderMapper.ToSpringHeadersContext> - Parameters:
pulsarMessage
- the Pulsar message whose headers are being mapped- Returns:
- optional context to pass through the mapping invocation
-
toSpringHeaderValue
protected Object toSpringHeaderValue(String name, String value, JsonPulsarHeaderMapper.ToSpringHeadersContext context) Description copied from class:AbstractPulsarHeaderMapper
Determine the Spring Messaging header value to use for a Pulsar header.- Specified by:
toSpringHeaderValue
in classAbstractPulsarHeaderMapper<JsonPulsarHeaderMapper.ToPulsarHeadersContext,
JsonPulsarHeaderMapper.ToSpringHeadersContext> - Parameters:
name
- the Pulsar header namevalue
- the Pulsar header valuecontext
- the optional context used for the mapping invocation- Returns:
- the Spring Messaging header value to use
-
trusted
-