From 3b62d78dc70d2b43af5998d427452246279363c7 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 10 Oct 2024 13:20:48 -0700 Subject: [PATCH] Re-export includingDefaultValueFields in deprecated state for important Cloud customer. PiperOrigin-RevId: 684555053 --- .../com/google/protobuf/util/JsonFormat.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 509258813283..b1ee0e5c0867 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 @@ -178,6 +178,35 @@ public Printer usingTypeRegistry(com.google.protobuf.TypeRegistry registry) { sortingMapKeys); } + /** + * Creates a new {@link Printer} that will always print fields unless they are a message type or + * in a oneof. + * + *

Note that this does print Proto2 Optional but does not print Proto3 Optional fields, as + * the latter is represented using a synthetic oneof. + * + *

The new Printer clones all other configurations from the current {@link Printer}. + * + * @deprecated This method is deprecated, and slated for removal in the next Java breaking + * change (5.x). Prefer {@link #alwaysPrintFieldsWithNoPresence} + */ + @Deprecated + public Printer includingDefaultValueFields() { + if (shouldPrintDefaults != ShouldPrintDefaults.ONLY_IF_PRESENT) { + throw new IllegalStateException( + "JsonFormat includingDefaultValueFields has already been set."); + } + return new Printer( + registry, + oldRegistry, + ShouldPrintDefaults.ALWAYS_PRINT_EXCEPT_MESSAGES_AND_ONEOFS, + ImmutableSet.of(), + preservingProtoFieldNames, + omittingInsignificantWhitespace, + printingEnumsAsInts, + sortingMapKeys); + } + /** * Creates a new {@link Printer} that will also print default-valued fields if their * FieldDescriptors are found in the supplied set. Empty repeated fields and map fields will be