Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

provide access to underlying *json.Decoder from JSONPb.NewDecoder #637

Merged

Conversation

jhump
Copy link
Contributor

@jhump jhump commented May 1, 2018

I am using the JSONPb marshaler in non-grpc-gateway server code to handle a mix of proto and non-proto types for JSON encoding/decoding.

I need to be able to control the underlying *json.Decoder, such as calling its UseNumber() method and being able to access its Buffered() data to resume reading from a stream after a JSON value has been decoded from it.

@@ -84,16 +87,24 @@ func (j *JSONPb) marshalNonProtoField(v interface{}) ([]byte, error) {
}

// Unmarshal unmarshals JSON "data" into "v"
// Currently it can marshal only proto.Message.
// TODO(yugui) Support fields of primitive types in a message.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these lines because they are not true anymore. There are even tests that verify that unmarshaling works for non-proto types.

@jhump
Copy link
Contributor Author

jhump commented May 1, 2018

@achew22 or @yugui, if you have a sec, maybe you could review this small PR.

@jhump jhump force-pushed the jh/access-to-underlying-json.decoder branch from 25508bd to 5f5bd5c Compare May 2, 2018 02:05
@codecov-io
Copy link

Codecov Report

Merging #637 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #637      +/-   ##
==========================================
+ Coverage   58.88%   58.91%   +0.02%     
==========================================
  Files          30       30              
  Lines        2853     2855       +2     
==========================================
+ Hits         1680     1682       +2     
  Misses       1010     1010              
  Partials      163      163
Impacted Files Coverage Δ
runtime/marshal_json.go 83.33% <ø> (ø) ⬆️
runtime/marshal_jsonpb.go 70% <100%> (+0.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c2b051d...5f5bd5c. Read the comment docs.

@achew22 achew22 merged commit 27c6d20 into grpc-ecosystem:master May 2, 2018
adasari pushed a commit to adasari/grpc-gateway that referenced this pull request Apr 9, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants