-
Notifications
You must be signed in to change notification settings - Fork 192
JSON serialization emitDefaults option #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
772ee3e
5c50a95
db5637f
7121dc7
d714dbc
c253b82
d3bd5ae
86af2f2
b622504
3cd3d15
ed9527e
89ba6cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
class JsonSerializationContext { | ||
final bool emitDefaults; | ||
|
||
JsonSerializationContext(this.emitDefaults); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,12 @@ BuilderInfo mockInfo(String className, CreateBuilderFunc create) { | |
..e(7, 'enm', PbFieldType.OE, | ||
defaultOrMaker: mockEnumValues.first, | ||
valueOf: (i) => mockEnumValues.firstWhereOrNull((e) => e.value == i), | ||
enumValues: mockEnumValues); | ||
enumValues: mockEnumValues) | ||
..a(8, 'dbl', PbFieldType.OD) | ||
..aOB(9, 'bl') | ||
..a<int>(10, 'byts', PbFieldType.OY) | ||
..m<String, String>(11, 'mp', | ||
keyFieldType: PbFieldType.OS, valueFieldType: PbFieldType.OS); | ||
} | ||
|
||
/// A minimal protobuf implementation for testing. | ||
|
@@ -49,6 +54,18 @@ abstract class MockMessage extends GeneratedMessage { | |
|
||
ProtobufEnum get enm => $_getN(5); | ||
bool get hasEnm => $_has(5); | ||
set enm(x) => setField(7, x); | ||
|
||
double get dbl => $_get(6, 0.0); | ||
set dbl(x) => setField(8, x); | ||
|
||
bool get bl => $_get(7, false); | ||
set bl(x) => setField(9, x); | ||
|
||
List<int> get byts => $_get(8, []); | ||
set byts(x) => setField(10, x); | ||
|
||
Map<String, String> get mp => $_getMap(9); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like you don't try to set the map field in the tests. Is there a reason for this? To make sure we handle maps correctly we should set the map field too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The map value is getting set, just in a different way... For consistency, I followed the existing example of how the int32s are set using the See here for an example of setting/testing the map field. With this in mind, it is currently being tested, but if it would be better to set the map differently, just let me know. |
||
|
||
@override | ||
GeneratedMessage clone() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.