Skip to content

Commit 8efbf8d

Browse files
committed
📝 documentation to avoid future issues like #1108
1 parent e5a67fc commit 8efbf8d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ Likewise, when calling `get<your_type>()`, the `from_json` method will be called
602602
Some important things:
603603

604604
* Those methods **MUST** be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined).
605+
* Those methods **MUST** be available (e.g., properly headers must be included) everywhere you use the implicit conversions. Look at [issue 1108](https://github.com./nlohmann/json/issues/1108) for errors that may occur otherwise.
605606
* When using `get<your_type>()`, `your_type` **MUST** be [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). (There is a way to bypass this requirement described later.)
606607
* In function `from_json`, use function [`at()`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a93403e803947b86f4da2d1fb3345cf2c.html#a93403e803947b86f4da2d1fb3345cf2c) to access the object values rather than `operator[]`. In case a key does not exist, `at` throws an exception that you can handle, whereas `operator[]` exhibits undefined behavior.
607608
* In case your type contains several `operator=` definitions, code like `your_variable = your_json;` [may not compile](https://github.com./nlohmann/json/issues/667). You need to write `your_variable = your_json.get<decltype your_variable>();` instead.

0 commit comments

Comments
 (0)