Closed inkychris closed 1 year ago
How does nlohmann-json handle dynamic_casts? (Sorry for the delayed response).
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.
Replaces use of
dynamic_cast
with member functions onschema
.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 theschema
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.