QProtobufJsonSerializer Class
The QProtobufJsonSerializer class is an interface that represents basic functions for serialization/deserialization of QProtobufMessage objects to JSON. More...
| Header: | #include <QProtobufJsonSerializer> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Protobuf)target_link_libraries(mytarget PRIVATE Qt6::Protobuf) |
| Since: | Qt 6.7 |
| Inherits: | QAbstractProtobufSerializer |
Reimplemented Public Functions
| virtual QAbstractProtobufSerializer::Error | lastError() const override |
| virtual QString | lastErrorString() const override |
Detailed Description
The QProtobufJsonSerializer class registers serializers/deserializers for classes implementing a protobuf message, inheriting QProtobufMessage. These classes are generated automatically, based on a .proto file, using the CMake function qt_add_protobuf or by running qtprotobufgen directly.
Depth limit
A message can contain other messages, and those can contain further messages, so the nesting of a message can be arbitrarily deep. Parsing deeply nested input uses a lot of stack, so a malicious or corrupt input could crash the application. To prevent this, the serializer limits the nesting depth of messages when it deserializes. By default, the limit is 100 levels, the same as the default in other protobuf implementations such as C++ and Java. When the limit is exceeded, deserialize() fails and lastError() returns QAbstractProtobufSerializer::Error::InvalidFormat.
You can change the limit with the QT_PROTOBUF_NESTING_LIMIT environment variable. The value must be an integer of at least 1. The limit only affects deserialize(), and does not affect serialize().
The environment variable is read once per process, the first time the limit is needed. If you change it later, the new value is not used. A value that is not an integer, or is smaller than 1, is ignored, and the default limit is used.
The top-level message is not counted: with a limit of N, a message can contain N levels of nested messages. Each map field entry whose value is a message counts as two levels: the entry and its value.
Note: The JSON parser has its own limit of 1024 nested JSON objects and arrays. Input nested deeper than that fails even if the depth limit is higher. A repeated message field adds an array level, so the effective message nesting can be lower than 1024.
Member Function Documentation
[override virtual] QAbstractProtobufSerializer::Error QProtobufJsonSerializer::lastError() const
Reimplements: QAbstractProtobufSerializer::lastError() const.
Returns the last deserialization error for the serializer instance.
See also lastErrorString().
[override virtual] QString QProtobufJsonSerializer::lastErrorString() const
Reimplements: QAbstractProtobufSerializer::lastErrorString() const.
Returns the last deserialization error string for the serializer instance.
See also lastError().
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.