From 8efbf8d7bb54d8506f8645d27b743091f3d7c071 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 28 May 2018 18:14:44 +0200 Subject: [PATCH] :memo: documentation to avoid future issues like #1108 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 74710bfe..691cd105 100644 --- a/README.md +++ b/README.md @@ -602,6 +602,7 @@ Likewise, when calling `get()`, the `from_json` method will be called Some important things: * 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). +* 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. * When using `get()`, `your_type` **MUST** be [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). (There is a way to bypass this requirement described later.) * 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. * 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();` instead.