Giter Site home page Giter Site logo

Comments (4)

stephenberry avatar stephenberry commented on June 9, 2024

This does seem like a useful feature to support. Are you also wanting null to be supported because this is an optional? It seems like empty quotes is more of an error and that null would be more appropriate. But, perhaps you're required to handle empty quotes and want to do so with an optional?

from glaze.

justend29 avatar justend29 commented on June 9, 2024

I agree - empty strings should by default produce an error when using quoted_num because you are explicitly stating "parse numbers that are enclosed in strings", which an empty string is not.

Nevertheless, handling an explicit null value seems the idiomatic way to convey no value, which is currently not supported with quoted_num. Would adding that support be appropriate?

from glaze.

stephanyuan avatar stephanyuan commented on June 9, 2024

Yeah, I actually am required to handle empty quotes rather than null, read the doc and thought optional would be my choice. But anyway, I agree on this point that empty quoted_num is more of an error.

Another point would be the inconsistent missing-key-error-handling between string type and quoted_num type when they are defined as nullable.

For example, say I have error_on_missing_keys set to true:

// missing string type key, glz::read returns success
{"num":"123"}  
struct msg1_t {
    std::string                num;
    std::optional<std::string> str;
};

// missing quoted_num type key, glz::read returns missing_key error
{"str":"abc"} 
struct msg2_t {
    std::optional<double> num;
    std::string           str;
};

from glaze.

stephenberry avatar stephenberry commented on June 9, 2024

In #932 I merged in support for the major features requested in this issue.

  • Wrappers like quoted_num now behave like nullable types when they contain a nullable type
  • error_on_missing_keys now doesn't error if the optional is not set, like other nullable types

I did not add support for parsing empty strings as null optionals. I feel like this is a corner case that probably should be handled through a custom parser using glz::custom or glz::to_json/glz::from_json.

I'm going to close this issue because of the major improvements, and if you need assistance creating a custom parser, feel free to post another issue or discussion.

from glaze.

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.