org.apache.kafka.connect.json.JsonConverter Java Examples

The following examples show how to use org.apache.kafka.connect.json.JsonConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MirusOffsetTool.java    From mirus with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static MirusOffsetTool newOffsetTool(Args args) throws IOException {
  // This needs to be the admin topic properties.
  // By default these are in the worker properties file, as this has the has admin producer and
  // consumer settings.  Separating these might be wise - also useful for storing state in
  // source cluster if it proves necessary.
  final Map<String, String> properties =
      !args.propertiesFile.isEmpty()
          ? Utils.propsToStringMap(Utils.loadProps(args.propertiesFile))
          : Collections.emptyMap();
  final DistributedConfig config = new DistributedConfig(properties);
  final KafkaOffsetBackingStore offsetBackingStore = new KafkaOffsetBackingStore();
  offsetBackingStore.configure(config);

  // Avoid initializing the entire Kafka Connect plugin system by assuming the
  // internal.[key|value].converter is org.apache.kafka.connect.json.JsonConverter
  final Converter internalConverter = new JsonConverter();
  internalConverter.configure(config.originalsWithPrefix("internal.key.converter."), true);

  final OffsetSetter offsetSetter = new OffsetSetter(internalConverter, offsetBackingStore);
  final OffsetFetcher offsetFetcher = new OffsetFetcher(config, internalConverter);
  final OffsetSerDe offsetSerDe = OffsetSerDeFactory.create(args.format);

  return new MirusOffsetTool(args, offsetFetcher, offsetSetter, offsetSerDe);
}
 
Example #2
Source File: TaskConfigTest.java    From mirus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void customConvertersShouldBeInstantiated() {
  properties = new HashMap<>();
  properties.put("source.key.converter", "org.apache.kafka.connect.json.JsonConverter");
  properties.put("source.value.converter", "org.apache.kafka.connect.json.JsonConverter");
  properties.put("source.header.converter", "org.apache.kafka.connect.json.JsonConverter");

  TaskConfig taskConfig = new TaskConfig(properties);
  assertThat(taskConfig.getKeyConverter(), instanceOf(JsonConverter.class));
  assertThat(taskConfig.getValueConverter(), instanceOf(JsonConverter.class));
  assertThat(taskConfig.getHeaderConverter(), instanceOf(JsonConverter.class));
}
 
Example #3
Source File: TigerGraphSinkTask.java    From ecosys with Apache License 2.0 5 votes vote down vote up
public TigerGraphSinkTask () {
    this.converter = new JsonConverter();
    this.conn = null;
    this.gson = new Gson();
    this.accumulated = 0;
    this.lastCommitTime = System.currentTimeMillis();
    this.ret = new StringBuilder();
    this.parseTime = 0;
}
 
Example #4
Source File: JsonMessageBuilder.java    From kafka-connect-mq-sink with Apache License 2.0 5 votes vote down vote up
public JsonMessageBuilder() {
    log.info("Building messages using com.ibm.eventstreams.connect.mqsink.builders.JsonMessageBuilder");
    converter = new JsonConverter();
    
    // We just want the payload, not the schema in the output message
    HashMap<String, String> m = new HashMap<>();
    m.put("schemas.enable", "false");

    // Convert the value, not the key (isKey == false)
    converter.configure(m, false);
}
 
Example #5
Source File: JsonRecordBuilder.java    From kafka-connect-mq-source with Apache License 2.0 5 votes vote down vote up
public JsonRecordBuilder() {
    log.info("Building records using com.ibm.eventstreams.connect.mqsource.builders.JsonRecordBuilder");
    converter = new JsonConverter();

    // We just want the payload, not the schema in the output message
    HashMap<String, String> m = new HashMap<>();
    m.put("schemas.enable", "false");

    // Convert the value, not the key (isKey == false)
    converter.configure(m, false);
}
 
Example #6
Source File: JsonEventParser.java    From kafka-connect-hbase with Apache License 2.0 5 votes vote down vote up
/**
 * default c.tor
 */
public JsonEventParser() {
    this.keyConverter = new JsonConverter();
    this.valueConverter = new JsonConverter();

    Map<String, String> props = new HashMap<>(1);
    props.put("schemas.enable", Boolean.FALSE.toString());

    this.keyConverter.configure(props, true);
    this.valueConverter.configure(props, false);

}
 
Example #7
Source File: KafkaSchemaWrappedSchema.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public KafkaSchemaWrappedSchema(org.apache.pulsar.kafka.shade.avro.Schema schema,
                                Converter converter) {
    Map<String, String> props = new HashMap<>();
    boolean isJsonConverter = converter instanceof JsonConverter;
    props.put(GenericAvroSchema.OFFSET_PROP, isJsonConverter ? "0" : "5");
    this.schemaInfo = SchemaInfo.builder()
            .name(isJsonConverter? "KafKaJson" : "KafkaAvro")
            .type(isJsonConverter ? SchemaType.JSON : SchemaType.AVRO)
            .schema(schema.toString().getBytes(UTF_8))
            .properties(props)
            .build();
}
 
Example #8
Source File: StructuredJsonLayoutPlugin.java    From common with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static StructuredLayout createLayout(
    @PluginElement("Properties") final Property[] properties) {
  final JsonConverter converter = new JsonConverter();
  converter.configure(
      Arrays.stream(properties).collect(
          Collectors.toMap(Property::getName, Property::getValue)
      ),
      false
  );
  return new StructuredLayout(struct -> converter.fromConnectData("", struct.schema(), struct));
}
 
Example #9
Source File: ExtJsonConverter.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
public ExtJsonConverter(RegistryService client) {
    super(client);
    this.jsonConverter = new JsonConverter();
    this.mapper = new ObjectMapper();
    this.formatStrategy = new PrettyFormatStrategy();
}
 
Example #10
Source File: SchemaMapper.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 4 votes vote down vote up
private JsonConverter createNewConverter() {
  JsonConverter result = new JsonConverter();
  result.configure(configs, false);
  return result;
}
 
Example #11
Source File: SchemaMapper.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 4 votes vote down vote up
public SchemaJsonSerializer(JsonConverter jsonConverter) {
  this.jsonConverter = jsonConverter;
}
 
Example #12
Source File: SchemaMapper.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 4 votes vote down vote up
public SchemaJsonDeserializer(JsonConverter jsonConverter) {
  this.jsonConverter = jsonConverter;
}
 
Example #13
Source File: OffsetSetterTest.java    From mirus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Before
public void setUp() {
  offsetSetter = new OffsetSetter(new JsonConverter(), kafkaOffsetBackingStore);
}
 
Example #14
Source File: CustomTransform.java    From kafka-connect-couchbase with Apache License 2.0 4 votes vote down vote up
private static JsonConverter newSchemalessJsonConverter() {
  JsonConverter converter = new JsonConverter();
  converter.configure(singletonMap("schemas.enable", false), false);
  return converter;
}