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
822b924d
Commit
822b924d
authored
Mar 01, 2018
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow list values to be null when parsing
parent
9dc0a4d5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
JsonParserTest.cs
csharp/src/Google.Protobuf.Test/JsonParserTest.cs
+16
-0
JsonParser.cs
csharp/src/Google.Protobuf/JsonParser.cs
+3
-2
No files found.
csharp/src/Google.Protobuf.Test/JsonParserTest.cs
View file @
822b924d
...
@@ -695,6 +695,22 @@ namespace Google.Protobuf
...
@@ -695,6 +695,22 @@ namespace Google.Protobuf
Assert
.
AreEqual
(
Value
.
ForList
(
Value
.
ForNumber
(
1
),
Value
.
ForString
(
"x"
)),
Value
.
Parser
.
ParseJson
(
"[1, \"x\"]"
));
Assert
.
AreEqual
(
Value
.
ForList
(
Value
.
ForNumber
(
1
),
Value
.
ForString
(
"x"
)),
Value
.
Parser
.
ParseJson
(
"[1, \"x\"]"
));
}
}
[
Test
]
public
void
Value_List_WithNullElement
()
{
var
expected
=
Value
.
ForList
(
Value
.
ForString
(
"x"
),
Value
.
ForNull
(),
Value
.
ForString
(
"y"
));
var
actual
=
Value
.
Parser
.
ParseJson
(
"[\"x\", null, \"y\"]"
);
Assert
.
AreEqual
(
expected
,
actual
);
}
[
Test
]
public
void
StructValue_NullElement
()
{
var
expected
=
Value
.
ForStruct
(
new
Struct
{
Fields
=
{
{
"x"
,
Value
.
ForNull
()
}
}
});
var
actual
=
Value
.
Parser
.
ParseJson
(
"{ \"x\": null }"
);
Assert
.
AreEqual
(
expected
,
actual
);
}
[
Test
]
[
Test
]
public
void
ParseListValue
()
public
void
ParseListValue
()
{
{
...
...
csharp/src/Google.Protobuf/JsonParser.cs
View file @
822b924d
...
@@ -264,11 +264,12 @@ namespace Google.Protobuf
...
@@ -264,11 +264,12 @@ namespace Google.Protobuf
return
;
return
;
}
}
tokenizer
.
PushBack
(
token
);
tokenizer
.
PushBack
(
token
);
if
(
token
.
Type
==
JsonToken
.
TokenType
.
Null
)
object
value
=
ParseSingleValue
(
field
,
tokenizer
);
if
(
value
==
null
)
{
{
throw
new
InvalidProtocolBufferException
(
"Repeated field elements cannot be null"
);
throw
new
InvalidProtocolBufferException
(
"Repeated field elements cannot be null"
);
}
}
list
.
Add
(
ParseSingleValue
(
field
,
tokenizer
)
);
list
.
Add
(
value
);
}
}
}
}
...
...
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