GithubHelp home page GithubHelp logo

Comments (4)

srikrsna-buf avatar srikrsna-buf commented on June 9, 2024

Thank you for opening the issue along with a pr!

The ignoreUnknownFields setting is to ignore any extra json fields of a message which are not part of the message definition. For example given the following proto:

message Some {
    string foo = 1;
}

If the json value the we receive is:

{"foo": "...", "bar": "..."}

Then bar is the unknown field, and that is ignored.

Coming to Struct, it is part of special types called the Well Known Types, it is designed to represent any json value. undefined is not a valid json value. For example, if I try to do JSON.parse('{"foo": undefined}') even js will throw an error.

If you are using TypeScript, then the JsonValue type ensures that a valid json value is passed to the method. The intention for providing a fromJson is to typically pass the result of JSON.parse where instead of the raw json string we have the parsed object. So I'd say this is working as intended.

from protobuf-es.

thesiti92 avatar thesiti92 commented on June 9, 2024

ok, we can work around it for now then. it would be helpful to at least have some flag to ignore the fields, or if you guys ever implement something like .toPlainObject and .fromPlainObject. We make extensive use of protobuf Structs and the current ways of manipulating them with protobuf-es are a bit cumbersome. either way thanks for the quick response!

from protobuf-es.

srikrsna-buf avatar srikrsna-buf commented on June 9, 2024

@thesiti92 Maybe toPlainMessage will be useful?

from protobuf-es.

thesiti92 avatar thesiti92 commented on June 9, 2024

oh nice, didnt realize you guys added that. I think for structs its a bit more effed because the plain message representation still looks like {kind: <string>, value: <value>} which isnt super ergonomic to work with. This is all perhaps a consequence of using protobuf structs in typescript at all haha

from protobuf-es.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.