Comments (4)
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.
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.
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.
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)
- Build and test for 32-bit in Actions
- std::pair arrays roundtrip
- `float` member issue with `clang++-15` and `g++-12` HOT 3
- `json_test.cpp(7840): warning C4267: '=': conversion from 'size_t' to 'uint16_t', possible loss of data` HOT 1
- glz::reader/glz::writer for incremental reading/writing HOT 5
- Partial read for BEVE
- glz::raw without quotes question HOT 1
- Binary serialization of hidden members HOT 2
- error: constructor priorities are not supported 3316 | const char* argv[]) HOT 3
- gcc and msvc compilation error with explicit constructors HOT 19
- Warnings & Errors in various configurations HOT 16
- rapidjson ĺŻšćŻ HOT 15
- How do I read an array of json objects in glaze? HOT 15
- field-based parse bifurcation HOT 1
- Add the library to nuget HOT 2
- Option to skip reading in null values
- calculate serialize size before serialization and serialize to pre-allocated memory HOT 4
- Option to use partial with char* or char[] HOT 3
- data_must_be_null_terminated issue HOT 1
- Raw char buffer handling HOT 1
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 glaze.