Class YamlCodec
- All Implemented Interfaces:
Codec
Chosen when a message is meant to be read by a person as much as by a program: a configuration change broadcast to a fleet, a deployment instruction, a command replayed by hand from a dead-letter queue. It is worth saying plainly that YAML costs more to parse than JSON and is a poor choice for high volume; it earns its place where somebody will actually look at the message.
Written in block style rather than flow style, which is the whole reason to pick YAML. Flow style would produce something very close to JSON and would leave nothing to justify the cost.
This codec never volunteers for a message whose sender set no content type. YAML is a superset of JSON, so its parser accepts JSON bytes quite happily and would answer for messages meant for the JSON codec. It would even give the right value — while recording that a YAML message had arrived, which is the sort of wrong that is discovered much later. So it claims only content types that say YAML.
-
Constructor Details
-
YamlCodec
public YamlCodec()Uses a mapper that writes block-style YAML and ignores unknown keys. -
YamlCodec
public YamlCodec(com.fasterxml.jackson.databind.ObjectMapper mapper) - Parameters:
mapper- the mapper to use; it must be built on aYAMLFactory, or this codec will announce YAML and write something else
-
-
Method Details
-
defaultMapper
public static com.fasterxml.jackson.databind.ObjectMapper defaultMapper()- Returns:
- a mapper that writes readable YAML and tolerates keys it does not know
-
contentType
- Specified by:
contentTypein interfaceCodec- Returns:
- the content type this codec produces, for example
application/json
-
encode
-
decode
-
canDecode
-
toString
-