pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
466 stars 134 forks source link

Replace dynamic_cast with member functions (#210) #211

Closed inkychris closed 1 year ago

inkychris commented 1 year ago

Replaces use of dynamic_cast with member functions on schema.

This is currently a minimal implementation, since most derived classes will return nullptr, but this is easy to remedy if the general solution is acceptable. This could be left as a pure virtual function in the schema class.

Both Issue 25 and 189 tests, and the JSON schema test suite pass locally. (Windows environment so not sure how tests are supposed to be run automatically).

Library now builds successfully without RTTI.

pboettch commented 1 year ago

How does nlohmann-json handle dynamic_casts? (Sorry for the delayed response).

inkychris commented 1 year ago

As far as I can tell, nlohmann-json doesn't use any dynamic casting. It's a bit of a heated topic but some consider dynamic casting to be a code smell, i.e. sub-optimal design. My solution is by no means optimal, being a "just add a function to all the types" solution, but I suspect a more proper solution would require a much larger change.