This microservice can encode and decode JSON messages received via HTTP or any other transport
Main configuration is done via setting following properties in codecSettings
block of a custom configuration:
- messageTypeDetection - determines how the codec will detect a type of incoming message
Can be one of the following:BY_HTTP_METHOD_AND_URI
- message type will be detected based on the values ofmethod
anduri
message metadata properties (default)BY_INNER_FIELD
- message type will be retrieved from a message field specified bymessageTypeField
settingCONSTANT
- message type for decode messages will be always the same, message type will be taken fromconstantMessageType
option
- messageTypeField - a JSON pointer to the field containing message type (used only if
messageTypeDetection
=BY_INNER_FIELD
). - constantMessageType - a constant message type for decode, if CONSTANT option is turned on
More information about JSON pointer can be found here.
Examples:
{ "simple": 42, "object": { "simple": 54 }, "simple_collection": [89, 5], "object_collection": [ { "simple": "test" } ] }
JSON pointer | Result |
---|---|
/simple | 42 |
/object/simple | 54 |
/simple_collection/1 | 5 |
/object_collection/0/simple | test |
- rejectUnexpectedFields - messages with unknown fields will be rejected during decoding (
true
by default) - treatSimpleValuesAsStrings - allows decoding of primitive values from JSON string e.g.
"1"
can be decoded as number,"true"
as boolean, etc (false
by default)
messageTypeDetection: BY_INNER_FIELD
messageTypeField: "messageType"
rejectUnexpectedFields: true
treatSimpleValuesAsStrings: false
messageTypeDetection: CONSTANT
constantMessageType: "TypeFromDictionary"
Codec will attempt to encode all parsed messages in a message group if their protocol is set to json
Messages will be encoded into raw messages containing byte-string with JSON.
Raw message metadata will contain uri
and method
properties if it was decoded from HTTP request
Codec will attempt to decode all raw messages in a message group as JSON.
If messageTypeDetection
is set to BY_HTTP_METHOD_AND_URI
these messages are required to have uri
and method
metadata properties.
Here's an example of infra-mgr
config required to deploy this service
apiVersion: th2.exactpro.com/v1
kind: Th2Box
metadata:
name: codec-json
spec:
image-name: ghcr.io/th2-net/th2-codec-json
image-version: 0.7.0
custom-config:
codecSettings:
messageTypeDetection: BY_INNER_FIELD
messageTypeField: "messageType"
rejectUnexpectedFields: true
treatSimpleValuesAsStrings: false
type: th2-codec
pins:
# encoder
- name: in_codec_encode
connection-type: mq
attributes:
- encoder_in
- subscribe
- group
- name: out_codec_encode
connection-type: mq
attributes:
- encoder_out
- publish
- group
# decoder
- name: in_codec_decode
connection-type: mq
attributes:
- decoder_in
- subscribe
- group
- name: out_codec_decode
connection-type: mq
attributes:
- decoder_out
- publish
- group
# encoder general (technical)
- name: in_codec_general_encode
connection-type: mq
attributes:
- general_encoder_in
- subscribe
- group
- name: out_codec_general_encode
connection-type: mq
attributes:
- general_encoder_out
- publish
- group
# decoder general (technical)
- name: in_codec_general_decode
connection-type: mq
attributes:
- general_decoder_in
- subscribe
- group
- name: out_codec_general_decode
connection-type: mq
attributes:
- general_decoder_out
- publish
- group
extended-settings:
service:
enabled: false
ignoreGradleMetadataRedirection is used for sonatype because Sailfish dependencies have constrains that interfere with BOM, so we exclude Gradle metadata for these repositories.
It's been verified that Sailfish itself is compatible with versions from BOM and therefore safe to use.
- Updated versions of common, BOM and sailfish.
- Kotlin updated to 1.6.21
- Updated versions of common, BOM and sailfish.
- Added metadata ignoring behavior to gradle for sailfish dependencies.
- Path to the message type did not work if it was a nested field
- Support for parameters substitution in URI.
- Codec core version updated from
4.3.0
to4.7.0
- rejection error message
- bump
com.exactpro.th2:common
dependency to3.32.0
- bump
com.exactpro.th2:bom
dependency to3.1.0
- bump
com.exactpro.th2:codec
dependency to4.3.0
- bump
com.exactpro.th2:common
dependency to3.31.1
- ability to decode messages with constant type
- bump
com.exactpro.th2:common
dependency to3.31.0
- ability to decode/encode simple values from JSON root
- update
th2-codec
version from 4.0.0 to 4.1.1 - update
sailfish
dependencies from 3.2.1622 to 3.2.1736 - update
common
version from 3.17.0 to 3.29.1
- The filter for pins by
message_type
is not working
- migrated to the
th2-codec
version 4.0.0
- ability to use a JSON pointer to specify the path to the field with message type
- parent event id loss fixed
- use newer version of
com.exactpro.th2:sailfish-utils
dependency
- use newer version of SF JSON codec which properly encodes decimals to strings
- use newer versions of th2 libraries
- ability to determine message type from message field