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

org.openfeed.client.api.impl.PbUtil Maven / Gradle / Ivy

The newest version!
package org.openfeed.client.api.impl;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import com.google.protobuf.MessageOrBuilder;
import com.google.protobuf.util.JsonFormat;
import com.google.protobuf.util.JsonFormat.Printer;

public class PbUtil {
	private static Printer printer = com.google.protobuf.util.JsonFormat.printer().omittingInsignificantWhitespace();
	private static JsonFormat.Parser parser = JsonFormat.parser().ignoringUnknownFields();

	public static String toJson(MessageOrBuilder msg) {
		try {
			return printer.print(msg);
		} catch (InvalidProtocolBufferException ignore) {
		}
		return null;
	}

	public static void decode(String json, Message.Builder builder) {
		try {
			parser.merge(json, builder);
		} catch (InvalidProtocolBufferException e) {
		}
	}

	private PbUtil() {
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy