From aabc6c411a4ae2c5b63124d4079ea9b0dc0879c7 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 15 Dec 2015 09:23:38 +0000 Subject: [PATCH 1/2] Make ToString() valid without a type registry This addresses issue #1008, by creating a JsonFormatter which is private and only different to JsonFormatter.Default in terms of reference equality. Other plausible designs: - The same, but expose the diagnostic-only formatter - Add something to settings to say "I don't have a type registry at all" - Change the behaviour of JsonFormatter.Default (bad idea IMO, as we really *don't* want the result of this used as regular JSON to be parsed) Note that just trying to find a separate fix to issue #933 and using that to override Any.ToString() differently wouldn't work for messages that *contain* an Any. Generated code changes follow in the next commit. --- .../WellKnownTypes/AnyTest.cs | 23 ++++++++ csharp/src/Google.Protobuf/JsonFormatter.cs | 54 +++++++++++++++++-- .../compiler/csharp/csharp_message.cc | 2 +- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs index 0a2b8b32e7..f3593e5faf 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs @@ -62,5 +62,28 @@ namespace Google.Protobuf.WellKnownTypes var unpacked = any.Unpack(); Assert.AreEqual(message, unpacked); } + + [Test] + public void ToString_WithValues() + { + var message = SampleMessages.CreateFullTestAllTypes(); + var any = Any.Pack(message); + var text = any.ToString(); + Assert.That(text, Is.StringContaining("\"@value\": \"" + message.ToByteString().ToBase64() + "\"")); + } + + [Test] + public void ToString_Empty() + { + var any = new Any(); + Assert.AreEqual("{ \"@type\": \"\", \"@value\": \"\" }", any.ToString()); + } + + [Test] + public void ToString_MessageContainingAny() + { + var message = new TestWellKnownTypes { AnyField = new Any() }; + Assert.AreEqual("{ \"anyField\": { \"@type\": \"\", \"@value\": \"\" } }", message.ToString()); + } } } diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index 45941b3919..7b99f31465 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -56,17 +56,19 @@ namespace Google.Protobuf public sealed class JsonFormatter { internal const string AnyTypeUrlField = "@type"; + internal const string AnyDiagnosticValueField = "@value"; internal const string AnyWellKnownTypeValueField = "value"; private const string TypeUrlPrefix = "type.googleapis.com"; private const string NameValueSeparator = ": "; private const string PropertySeparator = ", "; - private static JsonFormatter defaultInstance = new JsonFormatter(Settings.Default); - /// /// Returns a formatter using the default settings. /// - public static JsonFormatter Default { get { return defaultInstance; } } + public static JsonFormatter Default { get; } = new JsonFormatter(Settings.Default); + + // A JSON formatter which *only* exists + private static readonly JsonFormatter diagnosticFormatter = new JsonFormatter(Settings.Default); /// /// The JSON representation of the first 160 characters of Unicode. @@ -149,6 +151,29 @@ namespace Google.Protobuf return builder.ToString(); } + /// + /// Converts a message to JSON for diagnostic purposes with no extra context. + /// + /// + /// + /// This differs from calling on the default JSON + /// formatter in its handling of . As no type registry is available + /// in calls, the normal way of resolving the type of + /// an Any message cannot be applied. Instead, a JSON property named @value + /// is included with the base64 data from the property of the message. + /// + /// The value returned by this method is only designed to be used for diagnostic + /// purposes. It may not be parsable by , and may not be parsable + /// by other Protocol Buffer implementations. + /// + /// The message to format for diagnostic purposes. + /// The diagnostic-only JSON representation of the message + public static string ToDiagnosticString(IMessage message) + { + Preconditions.CheckNotNull(message, nameof(message)); + return diagnosticFormatter.Format(message); + } + private void WriteMessage(StringBuilder builder, IMessage message) { if (message == null) @@ -516,6 +541,12 @@ namespace Google.Protobuf private void WriteAny(StringBuilder builder, IMessage value) { + if (ReferenceEquals(this, diagnosticFormatter)) + { + WriteDiagnosticOnlyAny(builder, value); + return; + } + string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); string typeName = GetTypeName(typeUrl); @@ -544,6 +575,23 @@ namespace Google.Protobuf builder.Append(" }"); } + private void WriteDiagnosticOnlyAny(StringBuilder builder, IMessage value) + { + string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); + ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); + builder.Append("{ "); + WriteString(builder, AnyTypeUrlField); + builder.Append(NameValueSeparator); + WriteString(builder, typeUrl); + builder.Append(PropertySeparator); + WriteString(builder, AnyDiagnosticValueField); + builder.Append(NameValueSeparator); + builder.Append('"'); + builder.Append(data.ToBase64()); + builder.Append('"'); + builder.Append(" }"); + } + internal static string GetTypeName(String typeUrl) { string[] parts = typeUrl.Split('/'); diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 9c72043bbd..e0230a244b 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -353,7 +353,7 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { printer->Print( "public override string ToString() {\n" - " return pb::JsonFormatter.Default.Format(this);\n" + " return pb::JsonFormatter.ToDiagnosticString(this);\n" "}\n\n"); } From adee6fe33250502a497cac6dc6b259e2936cdf93 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 15 Dec 2015 09:24:04 +0000 Subject: [PATCH 2/2] Generated code changes from previous commit. --- csharp/src/AddressBook/Addressbook.cs | 9 ++- .../Conformance.cs | 10 +-- .../TestProtos/MapUnittestProto3.cs | 14 ++-- .../TestProtos/UnittestImportProto3.cs | 2 +- .../TestProtos/UnittestImportPublicProto3.cs | 2 +- .../TestProtos/UnittestIssues.cs | 20 +++--- .../TestProtos/UnittestProto3.cs | 70 +++++++++---------- .../TestProtos/UnittestWellKnownTypes.cs | 8 +-- .../Google.Protobuf/Reflection/Descriptor.cs | 44 ++++++------ .../src/Google.Protobuf/WellKnownTypes/Any.cs | 2 +- .../src/Google.Protobuf/WellKnownTypes/Api.cs | 6 +- .../WellKnownTypes/Duration.cs | 2 +- .../Google.Protobuf/WellKnownTypes/Empty.cs | 2 +- .../WellKnownTypes/FieldMask.cs | 2 +- .../WellKnownTypes/SourceContext.cs | 2 +- .../Google.Protobuf/WellKnownTypes/Struct.cs | 6 +- .../WellKnownTypes/Timestamp.cs | 2 +- .../Google.Protobuf/WellKnownTypes/Type.cs | 10 +-- .../WellKnownTypes/Wrappers.cs | 18 ++--- 19 files changed, 117 insertions(+), 114 deletions(-) diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs index d5455d8078..2c81004c5b 100644 --- a/csharp/src/AddressBook/Addressbook.cs +++ b/csharp/src/AddressBook/Addressbook.cs @@ -43,6 +43,9 @@ namespace Google.Protobuf.Examples.AddressBook { } #region Messages + /// + /// [START messages] + /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public sealed partial class Person : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Person()); @@ -143,7 +146,7 @@ namespace Google.Protobuf.Examples.AddressBook { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -302,7 +305,7 @@ namespace Google.Protobuf.Examples.AddressBook { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -426,7 +429,7 @@ namespace Google.Protobuf.Examples.AddressBook { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 50ce1de4f7..f135d7684a 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -284,7 +284,7 @@ namespace Conformance { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -532,7 +532,7 @@ namespace Conformance { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1544,7 +1544,7 @@ namespace Conformance { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2343,7 +2343,7 @@ namespace Conformance { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2471,7 +2471,7 @@ namespace Conformance { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs index 5ff47ed253..3e9999e4de 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs @@ -425,7 +425,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -633,7 +633,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -741,7 +741,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -851,7 +851,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1121,7 +1121,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1318,7 +1318,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1427,7 +1427,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs index f257b46ca2..72ada3de2c 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs @@ -110,7 +110,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs index 2881ca0f87..45f0e247c6 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs @@ -96,7 +96,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs index cf34e8bccd..9ac2d7ac15 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs @@ -126,7 +126,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -204,7 +204,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -282,7 +282,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -405,7 +405,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -511,7 +511,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -668,7 +668,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -831,7 +831,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -947,7 +947,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1056,7 +1056,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1279,7 +1279,7 @@ namespace UnitTest.Issues.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs index 04de603b8d..462ae9f95f 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs @@ -927,7 +927,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1600,7 +1600,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1736,7 +1736,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1873,7 +1873,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1980,7 +1980,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2070,7 +2070,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2162,7 +2162,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2291,7 +2291,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2421,7 +2421,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2547,7 +2547,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2669,7 +2669,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2883,7 +2883,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3107,7 +3107,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3278,7 +3278,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3400,7 +3400,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3506,7 +3506,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3608,7 +3608,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3704,7 +3704,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3807,7 +3807,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3913,7 +3913,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4016,7 +4016,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4119,7 +4119,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4222,7 +4222,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4325,7 +4325,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4486,7 +4486,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4780,7 +4780,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5140,7 +5140,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5414,7 +5414,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5554,7 +5554,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5647,7 +5647,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5723,7 +5723,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5799,7 +5799,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5875,7 +5875,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5951,7 +5951,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -6027,7 +6027,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs index 642e5f9126..c00b0f41c6 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs @@ -466,7 +466,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1106,7 +1106,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1625,7 +1625,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2213,7 +2213,7 @@ namespace Google.Protobuf.TestProtos { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 03685322a4..d29424ada4 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -225,7 +225,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -489,7 +489,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -827,7 +827,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1021,7 +1021,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1162,7 +1162,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1436,7 +1436,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1741,7 +1741,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1872,7 +1872,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2031,7 +2031,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2196,7 +2196,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2404,7 +2404,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -2863,7 +2863,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3302,7 +3302,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3596,7 +3596,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3845,7 +3845,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -3990,7 +3990,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4121,7 +4121,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4252,7 +4252,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4451,7 +4451,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4653,7 +4653,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -4823,7 +4823,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -5051,7 +5051,7 @@ namespace Google.Protobuf.Reflection { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs index 0b830b668b..efa60a6840 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs @@ -165,7 +165,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs index e9330e6932..1b925b9cbc 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs @@ -230,7 +230,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -503,7 +503,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -783,7 +783,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs index 42fda452d6..4eeff4f033 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs @@ -164,7 +164,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs index 92bc039734..d568a811df 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs @@ -94,7 +94,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs index 963b72bec1..0cd5952a5d 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs @@ -221,7 +221,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs index d53856427b..2972b34601 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs @@ -105,7 +105,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs index 73e3cae294..a811ea8b3f 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs @@ -136,7 +136,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -361,7 +361,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -555,7 +555,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs index 499b095006..adee4bb4c0 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs @@ -175,7 +175,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs index ef368bd392..a76d02b4c7 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs @@ -230,7 +230,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -522,7 +522,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -910,7 +910,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1098,7 +1098,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1244,7 +1244,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs index a70b2fb026..4314877273 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs @@ -117,7 +117,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -228,7 +228,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -339,7 +339,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -450,7 +450,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -561,7 +561,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -672,7 +672,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -783,7 +783,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -894,7 +894,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) { @@ -1005,7 +1005,7 @@ namespace Google.Protobuf.WellKnownTypes { } public override string ToString() { - return pb::JsonFormatter.Default.Format(this); + return pb::JsonFormatter.ToDiagnosticString(this); } public void WriteTo(pb::CodedOutputStream output) {