Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
454dbf16
Commit
454dbf16
authored
Jun 23, 2016
by
chezRong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added minified JSON formatting functionality with test
parent
2fe0556c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
JsonFormat.java
...il/src/main/java/com/google/protobuf/util/JsonFormat.java
+0
-0
JsonFormatTest.java
...rc/test/java/com/google/protobuf/util/JsonFormatTest.java
+58
-0
No files found.
java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
View file @
454dbf16
This diff is collapsed.
Click to expand it.
java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
View file @
454dbf16
...
...
@@ -140,6 +140,9 @@ public class JsonFormatTest extends TestCase {
private
String
toJsonString
(
Message
message
)
throws
IOException
{
return
JsonFormat
.
printer
().
print
(
message
);
}
private
String
toCompactJsonString
(
Message
message
)
throws
IOException
{
return
JsonFormat
.
printer
().
omittingInsignificantWhitespace
().
print
(
message
);
}
private
void
mergeFromJson
(
String
json
,
Message
.
Builder
builder
)
throws
IOException
{
JsonFormat
.
parser
().
merge
(
json
,
builder
);
...
...
@@ -1166,4 +1169,59 @@ public class JsonFormatTest extends TestCase {
JsonFormat
.
parser
().
merge
(
"{\"optional_int32\": 54321}"
,
builder
);
assertEquals
(
54321
,
builder
.
getOptionalInt32
());
}
public
void
testOmittingInsignificantWhiteSpace
()
throws
Exception
{
TestAllTypes
message
=
TestAllTypes
.
newBuilder
().
setOptionalInt32
(
12345
).
build
();
assertEquals
(
"{"
+
"\"optionalInt32\":12345"
+
"}"
,
JsonFormat
.
printer
().
omittingInsignificantWhitespace
().
print
(
message
));
TestAllTypes
message1
=
TestAllTypes
.
getDefaultInstance
();
assertEquals
(
"{}"
,
JsonFormat
.
printer
().
omittingInsignificantWhitespace
().
print
(
message1
));
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
newBuilder
();
setAllFields
(
builder
);
TestAllTypes
message2
=
builder
.
build
();
assertEquals
(
"{"
+
"\"optionalInt32\":1234,"
+
"\"optionalInt64\":\"1234567890123456789\","
+
"\"optionalUint32\":5678,"
+
"\"optionalUint64\":\"2345678901234567890\","
+
"\"optionalSint32\":9012,"
+
"\"optionalSint64\":\"3456789012345678901\","
+
"\"optionalFixed32\":3456,"
+
"\"optionalFixed64\":\"4567890123456789012\","
+
"\"optionalSfixed32\":7890,"
+
"\"optionalSfixed64\":\"5678901234567890123\","
+
"\"optionalFloat\":1.5,"
+
"\"optionalDouble\":1.25,"
+
"\"optionalBool\":true,"
+
"\"optionalString\":\"Hello world!\","
+
"\"optionalBytes\":\"AAEC\","
+
"\"optionalNestedMessage\":{"
+
"\"value\":100"
+
"},"
+
"\"optionalNestedEnum\":\"BAR\","
+
"\"repeatedInt32\":[1234,234],"
+
"\"repeatedInt64\":[\"1234567890123456789\",\"234567890123456789\"],"
+
"\"repeatedUint32\":[5678,678],"
+
"\"repeatedUint64\":[\"2345678901234567890\",\"345678901234567890\"],"
+
"\"repeatedSint32\":[9012,10],"
+
"\"repeatedSint64\":[\"3456789012345678901\",\"456789012345678901\"],"
+
"\"repeatedFixed32\":[3456,456],"
+
"\"repeatedFixed64\":[\"4567890123456789012\",\"567890123456789012\"],"
+
"\"repeatedSfixed32\":[7890,890],"
+
"\"repeatedSfixed64\":[\"5678901234567890123\",\"678901234567890123\"],"
+
"\"repeatedFloat\":[1.5,11.5],"
+
"\"repeatedDouble\":[1.25,11.25],"
+
"\"repeatedBool\":[true,true],"
+
"\"repeatedString\":[\"Hello world!\",\"ello world!\"],"
+
"\"repeatedBytes\":[\"AAEC\",\"AQI=\"],"
+
"\"repeatedNestedMessage\":[{"
+
"\"value\":100"
+
"},{"
+
"\"value\":200"
+
"}],"
+
"\"repeatedNestedEnum\":[\"BAR\",\"BAZ\"]"
+
"}"
,
toCompactJsonString
(
message2
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment