spring ProtobufJsonFormatMessageConverter 源码

  • 2022-08-08
  • 浏览 (321)

spring ProtobufJsonFormatMessageConverter 代码

文件路径:/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufJsonFormatMessageConverter.java

/*
 * Copyright 2002-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.messaging.converter;

import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.util.JsonFormat;

import org.springframework.lang.Nullable;

/**
 * Subclass of {@link ProtobufMessageConverter} for use with the official
 * {@code "com.google.protobuf:protobuf-java-util"} library for JSON support.
 *
 * <p>Most importantly, this class allows for custom JSON parser and printer
 * configurations through the {@link JsonFormat} utility. If no special parser
 * or printer configuration is given, default variants will be used instead.
 *
 * <p>Requires Protobuf 3.x and {@code "com.google.protobuf:protobuf-java-util"} 3.x,
 * with 3.3 or higher recommended.
 *
 * @author Rossen Stoyanchev
 * @since 5.2.2
 */
public class ProtobufJsonFormatMessageConverter extends ProtobufMessageConverter {

	/**
	 * Constructor with default instances of {@link com.google.protobuf.util.JsonFormat.Parser
	 * JsonFormat.Parser}, {@link com.google.protobuf.util.JsonFormat.Printer
	 * JsonFormat.Printer}, and {@link ExtensionRegistry}.
	 */
	public ProtobufJsonFormatMessageConverter(@Nullable ExtensionRegistry extensionRegistry) {
		this(null, null);
	}

	/**
	 * Constructor with given instances of {@link com.google.protobuf.util.JsonFormat.Parser
	 * JsonFormat.Parser}, {@link com.google.protobuf.util.JsonFormat.Printer
	 * JsonFormat.Printer}, and a default instance of {@link ExtensionRegistry}.
	 */
	public ProtobufJsonFormatMessageConverter(
			@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {

		this(parser, printer, null);
	}

	/**
	 * Constructor with given instances of {@link com.google.protobuf.util.JsonFormat.Parser
	 * JsonFormat.Parser}, {@link com.google.protobuf.util.JsonFormat.Printer
	 * JsonFormat.Printer}, and {@link ExtensionRegistry}.
	 */
	public ProtobufJsonFormatMessageConverter(@Nullable JsonFormat.Parser parser,
			@Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistry extensionRegistry) {

		super(new ProtobufJavaUtilSupport(parser, printer), extensionRegistry);
	}

}

相关信息

spring 源码目录

相关文章

spring AbstractJsonMessageConverter 源码

spring AbstractMessageConverter 源码

spring ByteArrayMessageConverter 源码

spring CompositeMessageConverter 源码

spring ContentTypeResolver 源码

spring DefaultContentTypeResolver 源码

spring GenericMessageConverter 源码

spring GsonMessageConverter 源码

spring JsonbMessageConverter 源码

spring KotlinSerializationJsonMessageConverter 源码

0  赞