All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.kafka.support.serializer.ToFromStringSerde Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
/*
 * Copyright 2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.kafka.support.serializer;

import java.util.Map;

import org.apache.kafka.common.serialization.Deserializer;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serializer;

import org.springframework.util.Assert;

/**
 * A Serde that delegates to a {@link ToStringSerializer} and
 * {@link ParseStringDeserializer}.
 *
 * @param  the type.
 *
 * @author Gary Russell
 * @since 2.5
 *
 */
public class ToFromStringSerde implements Serde {

	private final ToStringSerializer toStringSerializer;

	private final ParseStringDeserializer fromStringDeserializer;

	/**
	 * Construct an instance with the provided properties.
	 * @param toStringSerializer the {@link ToStringSerializer}.
	 * @param fromStringDeserializer the {@link ParseStringDeserializer}.
	 */
	public ToFromStringSerde(ToStringSerializer toStringSerializer,
			ParseStringDeserializer fromStringDeserializer) {

		Assert.notNull(toStringSerializer, "'toStringSerializer' must not be null.");
		Assert.notNull(fromStringDeserializer, "'fromStringDeserializer' must not be null.");
		this.toStringSerializer = toStringSerializer;
		this.fromStringDeserializer = fromStringDeserializer;
	}

	@Override
	public void configure(Map configs, boolean isKey) {
		this.toStringSerializer.configure(configs, isKey);
		this.fromStringDeserializer.configure(configs, isKey);
	}

	@Override
	public Serializer serializer() {
		return this.toStringSerializer;
	}

	@Override
	public Deserializer deserializer() {
		return this.fromStringDeserializer;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy