InvalidConversion is a dummy class: it’s declared but not defined. ArduinoJson uses this class to trigger a compilation error with a distinctive pattern.

Thanks to this class, when you try to perform an invalid conversion, you get an error like this one:

In file included from .../ArduinoJson/Array/ArrayIterator.hpp:8:0,
                 from .../ArduinoJson/Array/ArrayRef.hpp:8,
                 from .../ArduinoJson.hpp:17,
                 from .../ArduinoJson.h:9,
                 from MyProgram.ino:9:
.../ArduinoJson/Variant/JsonVariant.hpp: In instantiation of 'typename ArduinoJson6180_91::enable_if<((! ArduinoJson6180_91::is_same<T, char*>::value) && (! ArduinoJson6180_91::is_same<T, char>::value)), T>::type ArduinoJson6180_91::JsonVariantConst::as() const [with T = ArduinoJson6180_91::ObjectRef; typename ArduinoJson6180_91::enable_if<((! ArduinoJson6180_91::is_same<T, char*>::value) && (! ArduinoJson6180_91::is_same<T, char>::value)), T>::type = ArduinoJson6180_91::ObjectRef]':
MyProgram.ino:37:44:   required from here
.../ArduinoJson/Variant/JsonVariant.hpp:251:34: error: invalid use of incomplete type 'class ArduinoJson6180_91::InvalidConversion<ArduinoJson6180_91::JsonVariantConst, ArduinoJson6180_91::ObjectRef>'
     return Converter<T>::fromJson(*this);
            ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from .../ArduinoJson/Variant/JsonVariant.hpp:14:0,
                 from .../ArduinoJson/Array/ArrayIterator.hpp:8,
                 from .../ArduinoJson/Array/ArrayRef.hpp:8,
                 from .../ArduinoJson.hpp:17,
                 from .../ArduinoJson.h:9,
                 from MyProgram.ino:9:
.../ArduinoJson/Variant/Converter.hpp:14:7: note: declaration of 'class ArduinoJson6180_91::InvalidConversion<ArduinoJson6180_91::JsonVariantConst, ArduinoJson6180_91::ObjectRef>'
 class InvalidConversion;  // Error here? See https://arduinojson.org/v6/invalid-conversion/
       ^~~~~~~~~~~~~~~~~

As you can see, InvalidConversion is a template class that takes two arguments. The first is the original type, and the second is the type it’s converted to. Unfortunately, the error shows the internal names instead of the public names.

For example, after removing the namespaces in the error above, it says:

invalid use of incomplete type 'class InvalidConversion<JsonVariantConst, ObjectRef>'

The internal name JsonVariantConst corresponds to JsonVariantConst, and ObjectRef corresponds to JsonObject. Indeed, converting from JsonVariantConst to JsonObject is invalid because it would convert a read-only reference to a read-write reference.

To fix this issue, you must convert the read-only reference to a read-only reference. In our example, it means we must replace JsonObject with JsonObjectConst. So, somewhere in the program, there is a statement like variant.as<JsonObject>() or JsonObject obj = variant that must be changed into variant.as<JsonObjectConst>() or JsonObjectConst obj = variant.

Global warming stripes by Professor Ed Hawkins (University of Reading)