diff --git a/python/templates/Collection.cc.jinja2 b/python/templates/Collection.cc.jinja2 index 44b4c139d..c0b97441c 100644 --- a/python/templates/Collection.cc.jinja2 +++ b/python/templates/Collection.cc.jinja2 @@ -13,6 +13,10 @@ {{ include }} {% endfor %} +#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__) +#include "nlohmann/json.hpp" +#endif + // standard includes #include #include diff --git a/python/templates/Collection.h.jinja2 b/python/templates/Collection.h.jinja2 index 24265eef1..46d28d5ed 100644 --- a/python/templates/Collection.h.jinja2 +++ b/python/templates/Collection.h.jinja2 @@ -19,7 +19,7 @@ #include "podio/CollectionIDTable.h" #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__) -#include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #endif #include diff --git a/python/templates/MutableObject.cc.jinja2 b/python/templates/MutableObject.cc.jinja2 index 9ed099278..edbca8da9 100644 --- a/python/templates/MutableObject.cc.jinja2 +++ b/python/templates/MutableObject.cc.jinja2 @@ -8,6 +8,10 @@ {{ include }} {% endfor %} +#ifdef PODIO_JSON_OUTPUT && !defined(__CLING__) +#include "nlohmann/json.hpp" +#endif + #include {{ utils.namespace_open(class.namespace) }} diff --git a/python/templates/MutableObject.h.jinja2 b/python/templates/MutableObject.h.jinja2 index ab39778a0..b34b63a58 100644 --- a/python/templates/MutableObject.h.jinja2 +++ b/python/templates/MutableObject.h.jinja2 @@ -17,7 +17,7 @@ #include #ifdef PODIO_JSON_OUTPUT -#include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #endif {{ utils.forward_decls(forward_declarations) }} diff --git a/python/templates/Object.cc.jinja2 b/python/templates/Object.cc.jinja2 index 0d4b07b7e..37414ec52 100644 --- a/python/templates/Object.cc.jinja2 +++ b/python/templates/Object.cc.jinja2 @@ -8,6 +8,10 @@ {{ include }} {% endfor %} +#ifdef PODIO_JSON_OUTPUT && !defined(__CLING__) +#include "nlohmann/json.hpp" +#endif + #include {{ utils.namespace_open(class.namespace) }} diff --git a/python/templates/Object.h.jinja2 b/python/templates/Object.h.jinja2 index 0a6de9296..1e2562299 100644 --- a/python/templates/Object.h.jinja2 +++ b/python/templates/Object.h.jinja2 @@ -14,8 +14,8 @@ #include #include -#ifdef PODIO_JSON_OUTPUT -#include "nlohmann/json.hpp" +#ifdef PODIO_JSON_OUTPUT && !defined(__CLING__) +#include "nlohmann/json_fwd.hpp" #endif {{ utils.forward_decls(forward_declarations) }} diff --git a/python/templates/macros/declarations.jinja2 b/python/templates/macros/declarations.jinja2 index af46f499e..a0c976bc4 100644 --- a/python/templates/macros/declarations.jinja2 +++ b/python/templates/macros/declarations.jinja2 @@ -134,7 +134,7 @@ {%- endmacro %} {% macro json_output(type, prefix='') %} -#ifdef PODIO_JSON_OUTPUT +#ifdef PODIO_JSON_OUTPUT && !defined(__CLING__) void to_json(nlohmann::json& j, const {{ prefix }}{{ type }}& value); #endif {% endmacro %}