Overview
在本指南中,您可以了解如何指定要在JSON MongoDBKafka源 中使用的内置connector 格式化程序类。
JSON 格式化程序
JSON 格式化程序指定 JSON 数据的显示方式。 它们说明connector在输出数据时如何表示不同类型。
内置格式化程序
下表描述了源connector中可用的格式化程序类:
| 类 | 说明 | 
|---|---|
| 
 | 传统的严格 JSON 格式化程序。 | 
| 
 | 完全类型安全的扩展 JSON 格式化程序。 此格式化程序强调类型保留,并用 BSON 类型表示大多数值。 | 
| 
 | 简化的 JSON 格式化程序。 此格式化程序将 | 
示例
下表描述了本指南中的示例用于演示每种输出格式的示例文档的字段。 这些列描述了每个字段或嵌套字段的字段名称、值和类型。
| 名称 | 值 | 类型 | |
|---|---|---|---|
| 
 |  | 
 | |
| 
 |  | Array of: -  Decimal128($numberDecimal)-  Double($numberDouble) | |
| 
 |  | 
 | |
| 
 |  | 
 | |
| 
 |  | Document with fields: -  a:Boolean-  b:Int32($numberInt)-  c:String | 
默认 JSON 格式化程序
在源connector的配置属性中,设置以下属性以指定默认的JSON格式化程序:
"output.json.formatter": "com.mongodb.kafka.connect.source.json.formatter.DefaultJson" 
当您从 Kafka 主题输出样本文档内容时,输出会显示以下类型表示:
- ObjectId值及其 BSON 类型
- Decimal值及其 BSON 类型
- Binary值及其缓冲区string和二进制类型
- Date自 UNIX 纪元以来的毫秒值
{    "_id": {"$oid": "5f15aab12435743f9bd126a4"},    "w": [{"$numberDecimal": "12345.6789"}, 23.53],    "x": {"$binary": "SSBsb3ZlIGZvcm1hdHRpbmch", "$type": "00"},    "y": {"$date": 1683793627000},    "z": {"a": false, "b": 87, "c": "hello world"} } 
扩展 JSON 格式化程序
在源connector的配置属性中,设置以下属性以指定扩展JSON格式化程序:
"output.json.formatter": "com.mongodb.kafka.connect.source.json.formatter.ExtendedJson" 
当您从 Kafka 主题输出样本文档内容时,输出会显示以下类型表示:
- ObjectId值及其 BSON 类型
- Decimal值及其 BSON 类型
- Double值及其 BSON 类型
- Binary值及其缓冲区string和二进制类型
- Date自 UNIX 纪元以来的毫秒值
- Int32值及其 BSON 类型
{    "_id": {"$oid": "5f15aab12435743f9bd126a4"},    "w": [{"$numberDecimal": "12345.6789"}, {"$numberDouble": "23.53"}],    "x": {"$binary": "SSBsb3ZlIGZvcm1hdHRpbmch", "$type": "00"},    "y": {"$date": 1683793627000},    "z": {"a": false, "b": {"$numberInt": "87"}, "c": "hello world"} } 
简化的 JSON 格式化程序
在源connector的配置属性中,设置以下属性以指定简化的JSON格式化程序:
"output.json.formatter": "com.mongodb.kafka.connect.source.json.formatter.SimplifiedJson" 
当您从 Kafka 主题输出样本文档内容时,输出会显示以下类型表示:
- ObjectId十六进制string形式的值
- Decimalstring形式的值
- Binary值作为其缓冲区string
- Datestring形式的值
{    "_id": "5f15aab12435743f9bd126a4",    "w": ["12345.6789", 23.53],    "x": "SSBsb3ZlIGZvcm1hdHRpbmch",    "y": "2023-05-11T08:27:07Z",    "z": {"a": false, "b": 87, "c": "hello world"} }