From 4d98369f6d00dbdaa45ee2b91f1ec149a60ef905 Mon Sep 17 00:00:00 2001 From: Pradeep Gollakota Date: Fri, 18 Mar 2016 23:06:14 -0700 Subject: Allow custom URLs for Any in JsonFormat - Using custom URL for types in Any will no longer throw an InvalidProtocolBufferException in JsonFormat - Fixes #1128 --- java/util/src/main/java/com/google/protobuf/util/JsonFormat.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'java/util') diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java index d13ff0ed..c9a28c9e 100644 --- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java +++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java @@ -951,16 +951,15 @@ public class JsonFormat { } } - private static final String TYPE_URL_PREFIX = "type.googleapis.com"; - + private static String getTypeName(String typeUrl) throws InvalidProtocolBufferException { String[] parts = typeUrl.split("/"); - if (parts.length != 2 || !parts[0].equals(TYPE_URL_PREFIX)) { + if (parts.length == 1) { throw new InvalidProtocolBufferException( "Invalid type url found: " + typeUrl); } - return parts[1]; + return parts[parts.length - 1]; } private static class ParserImpl { -- cgit v1.2.3