That's all. When calling the json constructor with your type, your custom `to_json` method will be automatically called.
Likewise, when calling `get<your_type>()`, the `from_json` method will be called.
Some important things:
* Those methods **MUST** be in your type's namespace, or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined).
* When using `get<your_type>()`, `your_type`**MUST** be DefaultConstructible and CopyConstructible (There is a way to bypass those requirements described later)
#### How do I convert third-party types?
This requires a bit more advanced technique.
But first, let's see how this conversion mechanism works:
The library uses **JSON Serializers** to convert types to json.
The default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](http://en.cppreference.com/w/cpp/language/adl))
It is implemented like this (simplified):
```cpp
template<typenameT>
structadl_serializer
{
staticvoidto_json(json&j,constT&value)
{
// calls the "to_json" method in T's namespace
}
staticvoidfrom_json(constjson&j,T&value)
{
// same thing, but with the "from_json" method
}
};
```
This serializer works fine when you have control over the type's namespace.
However, what about `boost::optional`, or `std::filesystem::path` (C++17)?
Hijacking the `boost` namespace is pretty bad, and it's illegal to add something other than template specializations to `std`...
To solve this, you need to add a specialization of `adl_serializer` to the `nlohmann` namespace, here's an example:
```cpp
// partial specialization (full specialization works too)