Revert "Backport upstream changes to allow printing field names verbatim."
This reverts commit 6979a8253ba28d1cbe53d5cbec83faaf4491320e.
Replacing with merge from upstream.
Bug: 117607748
Test: m checkbuild
Change-Id: Idb49dde7db8d76e06f211e21db63ce3fbfad4a2e
diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.cc b/src/google/protobuf/util/internal/default_value_objectwriter.cc
index 22fa0e4..21d7a2e 100644
--- a/src/google/protobuf/util/internal/default_value_objectwriter.cc
+++ b/src/google/protobuf/util/internal/default_value_objectwriter.cc
@@ -64,7 +64,6 @@
type_(type),
current_(NULL),
root_(NULL),
- preserve_proto_field_names_(false),
field_scrub_callback_(NULL),
ow_(ow) {}
@@ -190,7 +189,6 @@
NodeKind kind, const DataPiece& data,
bool is_placeholder,
const vector<string>& path,
- bool preserve_proto_field_names,
FieldScrubCallBack* field_scrub_callback)
: name_(name),
type_(type),
@@ -199,7 +197,6 @@
data_(data),
is_placeholder_(is_placeholder),
path_(path),
- preserve_proto_field_names_(preserve_proto_field_names),
field_scrub_callback_(field_scrub_callback) {}
DefaultValueObjectWriter::Node* DefaultValueObjectWriter::Node::FindChild(
@@ -369,7 +366,7 @@
field.json_name(), field_type, kind,
kind == PRIMITIVE ? CreateDefaultDataPieceForField(field, typeinfo)
: DataPiece::NullData(),
- true, path, preserve_proto_field_names_, field_scrub_callback_));
+ true, path, field_scrub_callback_));
new_children.push_back(child.release());
}
// Adds all leftover nodes in children_ to the beginning of new_child.
@@ -465,8 +462,7 @@
if (current_ == NULL) {
vector<string> path;
root_.reset(new Node(name.ToString(), &type_, OBJECT, DataPiece::NullData(),
- false, path, preserve_proto_field_names_,
- field_scrub_callback_.get()));
+ false, path, field_scrub_callback_.get()));
root_->PopulateChildren(typeinfo_);
current_ = root_.get();
return this;
@@ -482,7 +478,6 @@
: NULL),
OBJECT, DataPiece::NullData(), false,
child == NULL ? current_->path() : child->path(),
- preserve_proto_field_names_,
field_scrub_callback_.get()));
child = node.get();
current_->AddChild(node.release());
@@ -514,8 +509,7 @@
if (current_ == NULL) {
vector<string> path;
root_.reset(new Node(name.ToString(), &type_, LIST, DataPiece::NullData(),
- false, path, preserve_proto_field_names_,
- field_scrub_callback_.get()));
+ false, path, field_scrub_callback_.get()));
current_ = root_.get();
return this;
}
@@ -525,7 +519,6 @@
google::protobuf::scoped_ptr<Node> node(
new Node(name.ToString(), NULL, LIST, DataPiece::NullData(), false,
child == NULL ? current_->path() : child->path(),
- preserve_proto_field_names_,
field_scrub_callback_.get()));
child = node.get();
current_->AddChild(node.release());
@@ -584,7 +577,6 @@
google::protobuf::scoped_ptr<Node> node(
new Node(name.ToString(), NULL, PRIMITIVE, data, false,
child == NULL ? current_->path() : child->path(),
- preserve_proto_field_names_,
field_scrub_callback_.get()));
child = node.get();
current_->AddChild(node.release());
diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h
index 7a925f7..1d85bed 100644
--- a/src/google/protobuf/util/internal/default_value_objectwriter.h
+++ b/src/google/protobuf/util/internal/default_value_objectwriter.h
@@ -122,11 +122,6 @@
// field_scrub_callback pointer is also transferred to this class
void RegisterFieldScrubCallBack(FieldScrubCallBackPtr field_scrub_callback);
- // If set to true, original proto field names are used
- void set_preserve_proto_field_names(bool value) {
- preserve_proto_field_names_ = value;
- }
-
private:
enum NodeKind {
PRIMITIVE = 0,
@@ -141,7 +136,6 @@
public:
Node(const string& name, const google::protobuf::Type* type, NodeKind kind,
const DataPiece& data, bool is_placeholder, const vector<string>& path,
- bool preserve_proto_field_names,
FieldScrubCallBack* field_scrub_callback);
virtual ~Node() {
for (int i = 0; i < children_.size(); ++i) {
@@ -218,9 +212,6 @@
// Path of the field of this node
std::vector<string> path_;
- // Whether to preserve original proto field names
- bool preserve_proto_field_names_;
-
// Pointer to function for determining whether a field needs to be scrubbed
// or not. This callback is owned by the creator of this node.
FieldScrubCallBack* field_scrub_callback_;
@@ -266,9 +257,6 @@
// The stack to hold the path of Nodes from current_ to root_;
std::stack<Node*> stack_;
- // Whether to preserve original proto field names
- bool preserve_proto_field_names_;
-
// Unique Pointer to function for determining whether a field needs to be
// scrubbed or not.
FieldScrubCallBackPtr field_scrub_callback_;
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc
index a9c5863..1f3781a 100644
--- a/src/google/protobuf/util/internal/protostream_objectsource.cc
+++ b/src/google/protobuf/util/internal/protostream_objectsource.cc
@@ -120,7 +120,6 @@
own_typeinfo_(true),
type_(type),
use_lower_camel_for_enums_(false),
- preserve_proto_field_names_(false),
recursion_depth_(0),
max_recursion_depth_(kDefaultMaxRecursionDepth) {
GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
@@ -134,7 +133,6 @@
own_typeinfo_(false),
type_(type),
use_lower_camel_for_enums_(false),
- preserve_proto_field_names_(false),
recursion_depth_(0),
max_recursion_depth_(kDefaultMaxRecursionDepth) {
GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
@@ -195,11 +193,7 @@
last_tag = tag;
field = FindAndVerifyField(type, tag);
if (field != NULL) {
- if (preserve_proto_field_names_) {
- field_name = field->name();
- } else {
- field_name = field->json_name();
- }
+ field_name = field->json_name();
}
}
if (field == NULL) {
@@ -634,8 +628,6 @@
// using a nested ProtoStreamObjectSource using our nested type information.
ProtoStreamObjectSource nested_os(&in_stream, os->typeinfo_, *nested_type);
- nested_os.set_use_lower_camel_for_enums(os->use_lower_camel_for_enums_);
- nested_os.set_preserve_proto_field_names(os->preserve_proto_field_names_);
// We manually call start and end object here so we can inject the @type.
ow->StartObject(field_name);
ow->RenderString("@type", type_url);
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h
index a6cee4e..d7d4347 100644
--- a/src/google/protobuf/util/internal/protostream_objectsource.h
+++ b/src/google/protobuf/util/internal/protostream_objectsource.h
@@ -110,11 +110,6 @@
use_lower_camel_for_enums_ = value;
}
- // Sets whether to use original proto field names
- void set_preserve_proto_field_names(bool value) {
- preserve_proto_field_names_ = value;
- }
-
// Sets the max recursion depth of proto message to be deserialized. Proto
// messages over this depth will fail to be deserialized.
// Default value is 64.
@@ -286,9 +281,6 @@
// Whether to render enums using lowerCamelCase. Defaults to false.
bool use_lower_camel_for_enums_;
- // Whether to preserve proto field names
- bool preserve_proto_field_names_;
-
// Tracks current recursion depth.
mutable int recursion_depth_;
diff --git a/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/src/google/protobuf/util/internal/protostream_objectsource_test.cc
index 4099b8f..3f6fdf9 100644
--- a/src/google/protobuf/util/internal/protostream_objectsource_test.cc
+++ b/src/google/protobuf/util/internal/protostream_objectsource_test.cc
@@ -100,8 +100,7 @@
: helper_(GetParam()),
mock_(),
ow_(&mock_),
- use_lower_camel_for_enums_(false),
- use_preserve_proto_field_names_(false) {
+ use_lower_camel_for_enums_(false) {
helper_.ResetTypeInfo(Book::descriptor());
}
@@ -122,7 +121,6 @@
google::protobuf::scoped_ptr<ProtoStreamObjectSource> os(
helper_.NewProtoSource(&in_stream, GetTypeUrl(descriptor)));
if (use_lower_camel_for_enums_) os->set_use_lower_camel_for_enums(true);
- if (use_preserve_proto_field_names_) os->set_preserve_proto_field_names(true);
os->set_max_recursion_depth(64);
return os->WriteTo(&mock_);
}
@@ -270,14 +268,11 @@
void UseLowerCamelForEnums() { use_lower_camel_for_enums_ = true; }
- void UsePreserveProtoFieldNames() { use_preserve_proto_field_names_ = true; }
-
testing::TypeInfoTestHelper helper_;
::testing::NiceMock<MockObjectWriter> mock_;
ExpectingObjectWriter ow_;
bool use_lower_camel_for_enums_;
- bool use_preserve_proto_field_names_;
};
INSTANTIATE_TEST_CASE_P(DifferentTypeInfoSourceTest,
@@ -498,16 +493,6 @@
DoTest(book, Book::descriptor());
}
-TEST_P(ProtostreamObjectSourceTest, UsePreserveProtoFieldNames) {
- Book book;
- book.set_snake_field("foo");
-
- UsePreserveProtoFieldNames();
-
- ow_.StartObject("")->RenderString("snake_field", "foo")->EndObject();
- DoTest(book, Book::descriptor());
-}
-
TEST_P(ProtostreamObjectSourceTest, CyclicMessageDepthTest) {
Cyclic cyclic;
cyclic.set_m_int(123);
@@ -717,48 +702,6 @@
DoTest(out, AnyOut::descriptor());
}
-TEST_P(ProtostreamObjectSourceAnysTest, LowerCamelEnumOutputSnakeCase) {
- AnyOut out;
- ::google::protobuf::Any* any = out.mutable_any();
-
- Book book;
- book.set_type(Book::arts_and_photography);
- any->PackFrom(book);
-
- UseLowerCamelForEnums();
-
- ow_.StartObject("")
- ->StartObject("any")
- ->RenderString("@type",
- "type.googleapis.com/proto_util_converter.testing.Book")
- ->RenderString("type", "artsAndPhotography")
- ->EndObject()
- ->EndObject();
-
- DoTest(out, AnyOut::descriptor());
-}
-
-TEST_P(ProtostreamObjectSourceAnysTest, UsePreserveProtoFieldNames) {
- AnyOut out;
- ::google::protobuf::Any* any = out.mutable_any();
-
- Book book;
- book.set_snake_field("foo");
- any->PackFrom(book);
-
- UsePreserveProtoFieldNames();
-
- ow_.StartObject("")
- ->StartObject("any")
- ->RenderString("@type",
- "type.googleapis.com/proto_util_converter.testing.Book")
- ->RenderString("snake_field", "foo")
- ->EndObject()
- ->EndObject();
-
- DoTest(out, AnyOut::descriptor());
-}
-
TEST_P(ProtostreamObjectSourceAnysTest, RecursiveAny) {
AnyOut out;
::google::protobuf::Any* any = out.mutable_any();
diff --git a/src/google/protobuf/util/internal/testdata/books.proto b/src/google/protobuf/util/internal/testdata/books.proto
index 95af37c..1cbbba4 100644
--- a/src/google/protobuf/util/internal/testdata/books.proto
+++ b/src/google/protobuf/util/internal/testdata/books.proto
@@ -63,9 +63,6 @@
}
optional Type type = 11;
- // Useful for testing JSON snake/camel-case conversions.
- optional string snake_field = 12;
-
extensions 200 to 499;
}
diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc
index d725757..2659320 100644
--- a/src/google/protobuf/util/json_util.cc
+++ b/src/google/protobuf/util/json_util.cc
@@ -79,16 +79,12 @@
google::protobuf::Type type;
RETURN_IF_ERROR(resolver->ResolveMessageType(type_url, &type));
converter::ProtoStreamObjectSource proto_source(&in_stream, resolver, type);
- proto_source.set_preserve_proto_field_names(
- options.preserve_proto_field_names);
io::CodedOutputStream out_stream(json_output);
converter::JsonObjectWriter json_writer(options.add_whitespace ? " " : "",
&out_stream);
if (options.always_print_primitive_fields) {
converter::DefaultValueObjectWriter default_value_writer(
resolver, type, &json_writer);
- default_value_writer.set_preserve_proto_field_names(
- options.preserve_proto_field_names);
return proto_source.WriteTo(&default_value_writer);
} else {
return proto_source.WriteTo(&json_writer);
diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h
index 83547c7..1718bfb 100644
--- a/src/google/protobuf/util/json_util.h
+++ b/src/google/protobuf/util/json_util.h
@@ -53,12 +53,9 @@
// set to 0 will be omitted. Set this flag to true will override the default
// behavior and print primitive fields regardless of their values.
bool always_print_primitive_fields;
- // Whether to preserve proto field names
- bool preserve_proto_field_names;
JsonOptions() : add_whitespace(false),
- always_print_primitive_fields(false),
- preserve_proto_field_names(false) {
+ always_print_primitive_fields(false) {
}
};
diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc
index e23bff4..a4d3cc9 100644
--- a/src/google/protobuf/util/json_util_test.cc
+++ b/src/google/protobuf/util/json_util_test.cc
@@ -131,42 +131,6 @@
"\"repeatedMessageValue\":[]"
"}",
ToJson(m, options));
- options.preserve_proto_field_names = true;
- m.set_string_value("i am a test string value");
- m.set_bytes_value("i am a test bytes value");
- EXPECT_EQ(
- "{\"bool_value\":false,"
- "\"int32_value\":0,"
- "\"int64_value\":\"0\","
- "\"uint32_value\":0,"
- "\"uint64_value\":\"0\","
- "\"float_value\":0,"
- "\"double_value\":0,"
- "\"string_value\":\"i am a test string value\","
- "\"bytes_value\":\"aSBhbSBhIHRlc3QgYnl0ZXMgdmFsdWU=\","
- "\"enum_value\":\"FOO\","
- "\"repeated_bool_value\":[],"
- "\"repeated_int32_value\":[],"
- "\"repeated_int64_value\":[],"
- "\"repeated_uint32_value\":[],"
- "\"repeated_uint64_value\":[],"
- "\"repeated_float_value\":[],"
- "\"repeated_double_value\":[],"
- "\"repeated_string_value\":[],"
- "\"repeated_bytes_value\":[],"
- "\"repeated_enum_value\":[],"
- "\"repeated_message_value\":[]"
- "}",
- ToJson(m, options));
-}
-
-TEST_F(JsonUtilTest, TestPreserveProtoFieldNames) {
- TestMessage m;
- m.mutable_message_value();
-
- JsonPrintOptions options;
- options.preserve_proto_field_names = true;
- EXPECT_EQ("{\"message_value\":{}}", ToJson(m, options));
}
TEST_F(JsonUtilTest, ParseMessage) {