소스 검색

Complete json serialization

- Implement maps json deserializer
- Migrate to https microjson
- Add tests

Fixes: #39
Alexey Edelev 4 년 전
부모
커밋
316ee667d1

+ 1 - 1
.gitmodules

@@ -6,4 +6,4 @@
 	url = https://github.com/google/googletest.git
 [submodule "3rdparty/microjson"]
 	path = 3rdparty/microjson
-	url = git@github.com:semlanik/microjson.git
+	url = https://github.com/semlanik/microjson.git

+ 1 - 1
3rdparty/microjson

@@ -1 +1 @@
-Subproject commit 9f403d6f144b573e81f408a0ea9c30135990b7ab
+Subproject commit f177d4d40ed84781e5ee75bd947c20a4041bb930

+ 1 - 1
CMakeLists.txt

@@ -17,7 +17,7 @@ find_package(Qt5 COMPONENTS Core Network Qml REQUIRED)
 if(NOT EXISTS "${QT_PROTOBUF_SOURCE_DIR}/3rdparty/microjson/CMakeLists.txt")
     message(FATAL_ERROR "microjson is not found. Please initialize microjson module: git submodule init 3rdparty/microjson")
 else()
-    add_subdirectory("${QT_PROTOBUF_SOURCE_DIR}/3rdparty/microjson")
+    add_subdirectory("${QT_PROTOBUF_SOURCE_DIR}/3rdparty/microjson" EXCLUDE_FROM_ALL)
 endif()
 
 if(Qt5Core_VERSION VERSION_LESS "5.12.4")

+ 2 - 2
src/protobuf/qabstractprotobufserializer.h

@@ -180,7 +180,7 @@ public:
      *        property value and write new property to \a object
      * \param[in] it Pointer to beging of buffer where object serialized data is located
      */
-    virtual void deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const = 0;
+    virtual bool deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const = 0;
 
     /*!
      * \brief serializeMapEnd Method called at the begining of map serialization
@@ -224,7 +224,7 @@ public:
      *
      * \see https://developers.google.com/protocol-buffers/docs/proto3#maps for details
      */
-    virtual void deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const = 0;
+    virtual bool deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const = 0;
 
     /*!
      * \brief serializeEnum Serializes enum value represented as int64 type

+ 12 - 9
src/protobuf/qabstractprotobufserializer_p.h

@@ -192,9 +192,10 @@ void deserializeList(const QtProtobuf::QAbstractProtobufSerializer *serializer,
 
     V *newValue = new V;
     QList<QSharedPointer<V>> list = previous.value<QList<QSharedPointer<V>>>();
-    serializer->deserializeListObject(newValue, V::protobufMetaObject, it);
-    list.append(QSharedPointer<V>(newValue));
-    previous.setValue(list);
+    if (serializer->deserializeListObject(newValue, V::protobufMetaObject, it)) {
+        list.append(QSharedPointer<V>(newValue));
+        previous.setValue(list);
+    }
 }
 
 /*!
@@ -212,9 +213,10 @@ void deserializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, Q
     QVariant key = QVariant::fromValue<K>(K());
     QVariant value = QVariant::fromValue<V>(V());
 
-    serializer->deserializeMapPair(key, value, it);
-    out[key.value<K>()] = value.value<V>();
-    previous = QVariant::fromValue<QMap<K, V>>(out);
+    if (serializer->deserializeMapPair(key, value, it)) {
+        out[key.value<K>()] = value.value<V>();
+        previous = QVariant::fromValue<QMap<K, V>>(out);
+    }
 }
 
 /*!
@@ -233,9 +235,10 @@ void deserializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, Q
     QVariant key = QVariant::fromValue<K>(K());
     QVariant value = QVariant::fromValue<V *>(nullptr);
 
-    serializer->deserializeMapPair(key, value, it);
-    out[key.value<K>()] = QSharedPointer<V>(value.value<V *>());
-    previous = QVariant::fromValue<QMap<K, QSharedPointer<V>>>(out);
+    if (serializer->deserializeMapPair(key, value, it)) {
+        out[key.value<K>()] = QSharedPointer<V>(value.value<V *>());
+        previous = QVariant::fromValue<QMap<K, QSharedPointer<V>>>(out);
+    }
 }
 
 /*!

+ 58 - 34
src/protobuf/qprotobufjsonserializer.cpp

@@ -257,6 +257,26 @@ public:
         return QVariant::fromValue(list);
     }
 
+    QVariant deserializeValue(int type, const QByteArray &data, microjson::JsonType jsonType) {
+        QVariant newValue;
+        auto &handler = QtProtobufPrivate::findHandler(type);
+        if (handler.deserializer) {
+            QtProtobuf::QProtobufSelfcheckIterator it(data);
+            QtProtobuf::QProtobufSelfcheckIterator last = it;
+            last += it.size();
+            while(it != last) {
+                handler.deserializer(qPtr, it, newValue);
+                qDebug() << "newValue" << newValue;
+            }
+        } else {
+            auto handler = handlers.find(type);
+            if (handler != handlers.end() && handler->second.deserializer) {
+                newValue = handler->second.deserializer(data);
+            }
+        }
+        return newValue;
+    }
+
     void deserializeObject(QObject *object, const QProtobufMetaObject &metaObject, const char *data, int size) {
         microjson::JsonObject obj = microjson::parseJsonObject(data, static_cast<size_t>(size));
 
@@ -266,35 +286,8 @@ public:
             if (propertyIndex >= 0) {
                 QMetaProperty metaProperty = metaObject.staticMetaObject.property(propertyIndex);
                 auto userType = metaProperty.userType();
-                auto &handler = QtProtobufPrivate::findHandler(userType);
                 QByteArray value = QByteArray::fromStdString(property.second.value);
-                if (handler.deserializer) {
-                    QVariant newValue;
-                    if (property.second.type == microjson::JsonArrayType) {
-                        microjson::JsonArray arrayValues = microjson::parseJsonArray(property.second.value.data(), property.second.value.size());
-                        if (arrayValues.size() > 0) {
-                            if (arrayValues[0].type == microjson::JsonObjectType) {
-                                for (auto &arrayValue : arrayValues) {
-                                    QByteArray arrayBuffer = QByteArray::fromStdString(arrayValue.value);
-                                    QtProtobuf::QProtobufSelfcheckIterator it(arrayBuffer);
-                                    handler.deserializer(qPtr, it, newValue);
-                                }
-                            } else {
-                                QtProtobuf::QProtobufSelfcheckIterator it(value);
-                                handler.deserializer(qPtr, it, newValue);
-                            }
-                        }
-                    } else {
-                        QtProtobuf::QProtobufSelfcheckIterator it(value);
-                        handler.deserializer(qPtr, it, newValue);
-                    }
-                    object->setProperty(name.c_str(), newValue);
-                } else {
-                    auto handler = handlers.find(metaProperty.userType());
-                    if (handler != handlers.end() && handler->second.deserializer) {
-                        object->setProperty(name.c_str(), handler->second.deserializer(value));
-                    }
-                }
+                object->setProperty(name.c_str(), deserializeValue(userType, value, property.second.type));
             }
         }
     }
@@ -332,6 +325,7 @@ QByteArray QProtobufJsonSerializer::serializeObject(const QObject *object, const
 void QProtobufJsonSerializer::deserializeObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const
 {
     dPtr->deserializeObject(object, metaObject, it.data(), it.size());
+    it += it.size();
 }
 
 QByteArray QProtobufJsonSerializer::serializeListBegin(const QProtobufMetaProperty &/*metaProperty*/) const
@@ -352,9 +346,23 @@ QByteArray QProtobufJsonSerializer::serializeListEnd(QByteArray &buffer, const Q
     return {"]"};
 }
 
-void QProtobufJsonSerializer::deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const
+bool QProtobufJsonSerializer::deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const
 {
-    dPtr->deserializeObject(object, metaObject, it.data(), it.size());
+    if (*it == '[') {
+        qDebug() << "Begin of list";
+        ++it;
+    }
+
+    size_t i = 0;
+    microjson::JsonProperty property;
+    if (microjson::extractValue(it.data(), static_cast<size_t>(it.size()), i, ']', property)) {
+        dPtr->deserializeObject(object, metaObject, it.data() + property.valueBegin, property.valueSize());
+    } else {
+        it += it.size();
+        return false;
+    }
+    it += i;
+    return true;
 }
 
 QByteArray QProtobufJsonSerializer::serializeMapBegin(const QProtobufMetaProperty &/*metaProperty*/) const
@@ -374,11 +382,24 @@ QByteArray QProtobufJsonSerializer::serializeMapEnd(QByteArray &buffer, const QP
     return {"}"};
 }
 
-void QProtobufJsonSerializer::deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const
+bool QProtobufJsonSerializer::deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const
 {
-    Q_UNUSED(key)
-    Q_UNUSED(value)
-    Q_UNUSED(it)
+    if (*it == '{') {
+        qDebug() << "Begin of map";
+        ++it;
+    }
+
+    size_t i = 0;
+    microjson::JsonProperty property;
+    if (microjson::extractProperty(it.data(), static_cast<size_t>(it.size()), i, '}', property)) {
+        key = dPtr->deserializeValue(key.userType(), QByteArray(it.data() + property.nameBegin, property.nameSize()), microjson::JsonStringType);
+        value = dPtr->deserializeValue(value.userType(), QByteArray(it.data() + property.valueBegin, property.valueSize()), property.type);
+    } else {
+        it += it.size();
+        return false;
+    }
+    it += i;
+    return true;
 }
 
 QByteArray QProtobufJsonSerializer::serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &/*metaProperty*/) const
@@ -404,6 +425,7 @@ QByteArray QProtobufJsonSerializer::serializeEnumList(const QList<int64> &values
 void QProtobufJsonSerializer::deserializeEnum(int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const
 {
     value = metaEnum.keyToValue(it.data());
+    it += it.size();
 }
 
 void QProtobufJsonSerializer::deserializeEnumList(QList<int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const
@@ -413,4 +435,6 @@ void QProtobufJsonSerializer::deserializeEnumList(QList<int64> &value, const QMe
     for (auto &arrayValue : arrayValues) {
         value.append(metaEnum.keyToValue(arrayValue.value.c_str()));
     }
+
+    it += it.size();
 }

+ 2 - 2
src/protobuf/qprotobufjsonserializer.h

@@ -53,13 +53,13 @@ protected:
     QByteArray serializeListObject(const QObject *object, const QProtobufMetaObject &metaObject, const QProtobufMetaProperty &metaProperty) const override;
     QByteArray serializeListEnd(QByteArray &buffer, const QProtobufMetaProperty &metaProperty) const override;
 
-    void deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const override;
+    bool deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeMapBegin(const QProtobufMetaProperty &metaProperty) const override;
     QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QProtobufMetaProperty &metaProperty) const override;
     QByteArray serializeMapEnd(QByteArray &buffer, const QProtobufMetaProperty &metaProperty) const override;
 
-    void deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const override;
+    bool deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
     QByteArray serializeEnumList(const QList<int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;

+ 4 - 4
src/protobuf/qprotobufselfcheckiterator.h

@@ -46,7 +46,7 @@ public:
     QProtobufSelfcheckIterator(const QProtobufSelfcheckIterator &other) : m_sizeLeft(other.m_sizeLeft)
       , m_containerSize(other.m_containerSize)
       , m_it(other.m_it) {
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize || m_sizeLeft < 0) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
     }
@@ -67,7 +67,7 @@ public:
 
     QProtobufSelfcheckIterator &operator --() {
         ++m_sizeLeft;
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
         --m_it;
@@ -85,7 +85,7 @@ public:
 
     QProtobufSelfcheckIterator &operator -=(int count) {
         m_sizeLeft += count;
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
         m_it -= count;
@@ -99,7 +99,7 @@ public:
 
         m_containerSize = other.m_containerSize;
         m_sizeLeft = other.m_sizeLeft;
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize || m_sizeLeft < 0) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
         m_it = other.m_it;

+ 4 - 2
src/protobuf/qprotobufserializer.cpp

@@ -119,9 +119,10 @@ QByteArray QProtobufSerializer::serializeListObject(const QObject *object, const
     return serializeObject(object, metaObject, metaProperty);
 }
 
-void QProtobufSerializer::deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const
+bool QProtobufSerializer::deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const
 {
     deserializeObject(object, metaObject, it);
+    return true;
 }
 
 QByteArray QProtobufSerializer::serializeMapPair(const QVariant &key, const QVariant &value, const QProtobufMetaProperty &metaProperty) const
@@ -131,9 +132,10 @@ QByteArray QProtobufSerializer::serializeMapPair(const QVariant &key, const QVar
     return result;
 }
 
-void QProtobufSerializer::deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const
+bool QProtobufSerializer::deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const
 {
     dPtr->deserializeMapPair(key, value, it);
+    return true;
 }
 
 QByteArray QProtobufSerializer::serializeEnum(int64 value, const QMetaEnum &/*metaEnum*/, const QtProtobuf::QProtobufMetaProperty &metaProperty) const

+ 2 - 2
src/protobuf/qprotobufserializer.h

@@ -49,10 +49,10 @@ protected:
     void deserializeObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeListObject(const QObject *object, const QProtobufMetaObject &metaObject, const QProtobufMetaProperty &metaProperty) const override;
-    void deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const override;
+    bool deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QProtobufMetaProperty &metaProperty) const override;
-    void deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const override;
+    bool deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
     QByteArray serializeEnumList(const QList<int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;

+ 150 - 110
tests/test_protobuf/jsondeserializationtest.cpp

@@ -413,127 +413,167 @@ TEST_F(JsonDeserializationTest, SimpleEnumListMessageTest)
 TEST_F(JsonDeserializationTest, RepeatedComplexMessageTest)
 {
     RepeatedComplexMessage test;
-    test.deserialize(serializer.get(), "{\"testRepeatedComplex\":[{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":25},{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":25},{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":25}]}");
+    test.deserialize(serializer.get(), "{\"testRepeatedComplex\":[{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":25},{\"testComplexField\":{\"testFieldString\":\"\"},\"testFieldInt\":25},{\"testComplexField\":{\"testFieldString\":\"qwerty\"},\"testFieldInt\":25}]}");
     ASSERT_EQ(test.testRepeatedComplex().size(), 3);
     EXPECT_EQ(test.testRepeatedComplex()[0]->testFieldInt(), 25);
     EXPECT_EQ(test.testRepeatedComplex()[1]->testFieldInt(), 25);
     EXPECT_EQ(test.testRepeatedComplex()[2]->testFieldInt(), 25);
     EXPECT_STREQ(test.testRepeatedComplex()[0]->testComplexField().testFieldString().toStdString().c_str(), "qwerty");
-    EXPECT_STREQ(test.testRepeatedComplex()[1]->testComplexField().testFieldString().toStdString().c_str(), "qwerty");
+    EXPECT_STREQ(test.testRepeatedComplex()[1]->testComplexField().testFieldString().toStdString().c_str(), "");
     EXPECT_STREQ(test.testRepeatedComplex()[2]->testComplexField().testFieldString().toStdString().c_str(), "qwerty");
 
     test.deserialize(serializer.get(), "{\"testRepeatedComplex\":[]}");
     EXPECT_TRUE(test.testRepeatedComplex().isEmpty());
 }
 
-//TEST_F(JsonDeserializationTest, SimpleFixed32StringMapSerializeTest)
-//{
-//    SimpleFixed32StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleSFixed32StringMapSerializeTest)
-//{
-//    SimpleSFixed32StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleInt32StringMapSerializeTest)
-//{
-//    SimpleInt32StringMapMessage test;
-//    test.setMapField({{-10, {"minus ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleSInt32StringMapSerializeTest)
-//{
-//    SimpleSInt32StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleUInt32StringMapSerializeTest)
-//{
-//    SimpleUInt32StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleFixed64StringMapSerializeTest)
-//{
-//    SimpleFixed64StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleSFixed64StringMapSerializeTest)
-//{
-//    SimpleSFixed64StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleInt64StringMapSerializeTest)
-//{
-//    SimpleInt64StringMapMessage test;
-//    test.setMapField({{-10, {"minus ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleSInt64StringMapSerializeTest)
-//{
-//    SimpleSInt64StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {-42, {"minus fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleUInt64StringMapSerializeTest)
-//{
-//    SimpleUInt64StringMapMessage test;
-//    test.setMapField({{10, {"ten"}}, {42, {"fourty two"}}, {15, {"fifteen"}}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
-//}
-
-//TEST_F(JsonDeserializationTest, SimpleStringStringMapSerializeTest)
-//{
-//    SimpleStringStringMapMessage test;
-//    test.setMapField({{"ben", "ten"}, {"what is the answer?", "fourty two"}, {"sweet", "fifteen"}});
-//    QByteArray result = test.serialize(serializer.get());
-
-//    ASSERT_STREQ(result.toStdString().c_str(),
-//                 "{\"mapField\":{\"ben\":\"ten\",\"sweet\":\"fifteen\",\"what is the answer?\":\"fourty two\"}}");
-//}
+TEST_F(JsonDeserializationTest, SimpleFixed32StringMapSerializeTest)
+{
+    SimpleFixed32StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\",\"0\":\"\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 4);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+    EXPECT_STREQ(test.mapField()[0].toStdString().c_str(), "");
+}
+
+TEST_F(JsonDeserializationTest, SimpleSFixed32StringMapSerializeTest)
+{
+    SimpleSFixed32StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+}
+
+TEST_F(JsonDeserializationTest, SimpleInt32StringMapSerializeTest)
+{
+    SimpleInt32StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[-10].toStdString().c_str(), "minus ten");
+    EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleSInt32StringMapSerializeTest)
+{
+    SimpleSInt32StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleUInt32StringMapSerializeTest)
+{
+    SimpleUInt32StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleFixed64StringMapSerializeTest)
+{
+    SimpleFixed64StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleSFixed64StringMapSerializeTest)
+{
+    SimpleSFixed64StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleInt64StringMapSerializeTest)
+{
+    SimpleInt64StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[-10].toStdString().c_str(), "minus ten");
+    EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleSInt64StringMapSerializeTest)
+{
+    SimpleSInt64StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"-42\":\"minus fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[-42].toStdString().c_str(), "minus fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleUInt64StringMapSerializeTest)
+{
+    SimpleUInt64StringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"42\":\"fourty two\",\"10\":\"ten\",\"15\":\"fifteen\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()[10].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()[42].toStdString().c_str(), "fourty two");
+    EXPECT_STREQ(test.mapField()[15].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
+
+TEST_F(JsonDeserializationTest, SimpleStringStringMapSerializeTest)
+{
+    SimpleStringStringMapMessage test;
+    test.deserialize(serializer.get(), "{\"mapField\":{\"ben\":\"ten\",\"sweet\":\"fifteen\",\"what is the answer?\":\"fourty two\"}}");
+
+    ASSERT_EQ(test.mapField().size(), 3);
+    EXPECT_STREQ(test.mapField()["ben"].toStdString().c_str(), "ten");
+    EXPECT_STREQ(test.mapField()["what is the answer?"].toStdString().c_str(), "fourty two");
+    EXPECT_STREQ(test.mapField()["sweet"].toStdString().c_str(), "fifteen");
+
+    test.deserialize(serializer.get(), "{\"mapField\":{}}");
+    ASSERT_EQ(test.mapField().size(), 0);
+}
 
 }
 }

+ 4 - 2
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufjsonserializerimpl.cpp

@@ -76,13 +76,14 @@ QByteArray QProtobufJsonSerializerImpl::serializeListObject(const QObject *objec
     return QByteArray();
 }
 
-void QProtobufJsonSerializerImpl::deserializeListObject(QObject *object,
+bool QProtobufJsonSerializerImpl::deserializeListObject(QObject *object,
                                                         const QtProtobuf::QProtobufMetaObject &metaObject,
                                                         QtProtobuf::QProtobufSelfcheckIterator &it) const
 {
     Q_UNUSED(object)
     Q_UNUSED(it)
     Q_UNUSED(metaObject)
+    return true;
 }
 
 QByteArray QProtobufJsonSerializerImpl::serializeMapPair(const QVariant &key, const QVariant &value,
@@ -94,12 +95,13 @@ QByteArray QProtobufJsonSerializerImpl::serializeMapPair(const QVariant &key, co
     return QByteArray();
 }
 
-void QProtobufJsonSerializerImpl::deserializeMapPair(QVariant &key, QVariant &value,
+bool QProtobufJsonSerializerImpl::deserializeMapPair(QVariant &key, QVariant &value,
                                                      QtProtobuf::QProtobufSelfcheckIterator &it) const
 {
     Q_UNUSED(key)
     Q_UNUSED(value)
     Q_UNUSED(it)
+    return true;
 }
 
 QByteArray QProtobufJsonSerializerImpl::serializeEnum(QtProtobuf::int64 value,

+ 2 - 2
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufjsonserializerimpl.h

@@ -49,10 +49,10 @@ protected:
     void deserializeObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeListObject(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
-    void deserializeListObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+    bool deserializeListObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
-    void deserializeMapPair(QVariant &key, QVariant &value, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+    bool deserializeMapPair(QVariant &key, QVariant &value, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
     QByteArray serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;

+ 4 - 2
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufserializerimpl.cpp

@@ -78,11 +78,12 @@ QByteArray QProtobufSerializerImpl::serializeListObject(const QObject *object,
     return serializeObject(object, metaObject, metaProperty);
 }
 
-void QProtobufSerializerImpl::deserializeListObject(QObject *object,
+bool QProtobufSerializerImpl::deserializeListObject(QObject *object,
                                                     const QtProtobuf::QProtobufMetaObject &metaObject,
                                                     QtProtobuf::QProtobufSelfcheckIterator &it) const
 {
     deserializeObject(object, metaObject, it);
+    return true;
 }
 
 QByteArray QProtobufSerializerImpl::serializeMapPair(const QVariant &key,
@@ -95,13 +96,14 @@ QByteArray QProtobufSerializerImpl::serializeMapPair(const QVariant &key,
     return QByteArray();
 }
 
-void QProtobufSerializerImpl::deserializeMapPair(QVariant &key,
+bool QProtobufSerializerImpl::deserializeMapPair(QVariant &key,
                                                  QVariant &value,
                                                  QtProtobuf::QProtobufSelfcheckIterator &it) const
 {
     Q_UNUSED(value)
     Q_UNUSED(it)
     Q_UNUSED(key)
+    return true;
 }
 
 QByteArray QProtobufSerializerImpl::serializeEnum(QtProtobuf::int64 value,

+ 2 - 2
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufserializerimpl.h

@@ -45,10 +45,10 @@ protected:
     void deserializeObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeListObject(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
-    void deserializeListObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+    bool deserializeListObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
-    void deserializeMapPair(QVariant &key, QVariant &value, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+    bool deserializeMapPair(QVariant &key, QVariant &value, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
 
     QByteArray serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
     QByteArray serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;