Comments (2)
Digging a bit further, I'm not certain if this issue should be filed here or in the google/apitools repository.
I've found that some fields actually encode this as expected -- our Object
messages contain a separate metadata
field -- this is a repeated field containing instances of a separate message type, MetadataValue, which is decorated with an apitools function called MapUnrecognizedFields. It seems that if you a supply a value of None for one of these unrecognized fields, it will be JSON-encoded as null, rather than omitting the key/value pair altogether.
As an example, when encoding an Object
message containing one of these (with a key of "foo" and a value of None) to JSON, the value of null will be present, rather than omitting the attribute:
(Pdb) obj.metadata = apitools_messages.Object.MetadataValue()
(Pdb) obj.metadata.additionalProperties = []
(Pdb) obj
<Object
acl: []
metadata: <MetadataValue
additionalProperties: []>>
(Pdb) obj.metadata.additionalProperties.append(apitools_messages.Object.MetadataValue.AdditionalProperty(key='foo', value=None))
(Pdb) obj
<Object
acl: []
metadata: <MetadataValue
additionalProperties: [<AdditionalProperty
key: 'foo'>]>>
(Pdb) encoding.MessageToJson(obj)
'{"metadata": {"foo": null}}'
Although this encoding
module is defined within apitools here, and looks to be its own extension of protorpc's ProtoJson class, so probably outside the scope of this repository.
from protorpc.
Upon further investigation, it looks like apitools has an IncludeFields method that takes care of this:
https://github.com/google/apitools/blob/2bfa257a65e335ef67afc9f135c7796f47f85535/apitools/base/py/base_api.py#L356
from protorpc.
Related Issues (17)
- 0.11.0 release breaks apitools 0.4.11 HOT 4
- Please add per-file licenses HOT 5
- UnicodeEncodeError in logging statements HOT 1
- Does the Webapp service handler code support Webapp2?
- README.md is empty
- six 1.11.0 causes TypeError: Error when calling the metaclass bases
- Non-Unicode strings are silently ignored in StringFields
- Bazel support?
- Storing protos in Google Cloud Datastore?
- Bring `protorpc` Python3 support.
- ProtoRPC type miss match
- protorpc source distributions (.tar.gz) do not include subdirectories, e.g. "wsgi" HOT 1
- Python 3.7+ support HOT 1
- NameError: global name 'Enum' is not defined HOT 20
- How you import ProtocolBuffer? HOT 1
- Empty messages skip validation in protojson.decode_message
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protorpc.