Git Product home page Git Product logo

Comments (4)

Skycoder42 avatar Skycoder42 commented on July 20, 2024

The easiest way would be to simply remove all unneeded types from the src/jsonserializer/typesplit.pri file.

You could even remove almost everything from the file if you don't want anything registered at all. However, the generation of the primary hook itself must remain, even as empty function, as otherwise there will be linker errors. That would reduce the file to the following:

isEmpty(QT_JSONSERIALIZER_REGPATH): QT_JSONSERIALIZER_REGPATH = $$OUT_PWD/.reggen
mkpath($$QT_JSONSERIALIZER_REGPATH)

startup_hookfile = "void qtJsonSerializerRegisterTypes() {}"
out_file = $$QT_JSONSERIALIZER_REGPATH/qjsonconverterreg_all.cpp
!exists($$out_file):!write_file($$out_file, startup_hookfile):error("Failed to create $$out_file")
GENERATED_SOURCES += $$out_file

from qtjsonserializer.

useful-friend avatar useful-friend commented on July 20, 2024

Thanks for the code.
It drastically reduced the binary size but I see that all the de/serialize processes in my code are working well even with nothing being registered and I don't know why.
Another thing that crossed my mind was removing type converters that I don't need in typeconverters.pri.
I wanted to know what are those files and ask if it is ok to remove them?
I would appreciate it if you describe the mechanism of type converters and their registrations.

from qtjsonserializer.

Skycoder42 avatar Skycoder42 commented on July 20, 2024

The library basically has two kinds of conversion (which, unfortunately, are all named "typeconverters" due to a shortsight of mine)

  1. Container converters
  2. Serializers

Container converters

The first group is what is generated with the typesplit.pri file and is responsible for generalizing generic types, e.g.:

QList<int> <=> QVariantList
QMap<QString, double> <=> QVariantMap
....

This allows the library to de/serialize any generic type, as long as such a converter has been registered for that type. You can register those manually via QJsonSerializer::register* methods. Please note that this part has drastically changed with the 4.0.0 release and is no longer valid, but for your version, that's the task these methods (and the startup hook) have.

Removing the hook simply means, that you cannot convert generic containers anymore. If you have for example a QList<int> somewhere, it will stop working, unless you manually call QJsonSerializer::registerListConverters<int> in your code. The hook is simply provided to automatically do these registrations for common Qt types so you don't have to.

Serializers

The QJsonTypeConverter classes in contrast are responsible for doing the actual conversion between C++ and JSON. Some basic types are converted implicitly, but most types, (e.g. lists, objects, ...) need a converter. This split between the core serializer and the converters makes the library flexible and easy to extend.

Some of these converters require a certain "Container converter" to be registered for work. For example, the QJsonListConverter can de/serialize any QList<T>, as long as T was registered via QJsonSerializer::registerListConverters<T>. It can also work with QVariantList, so if you want to avoid the conversion all together, use QVariantList properties and you are good.

You can simply remove any converter from typeconverters.pri you don't need, e.g. if you do not use QVersionNumber, you can remove the QJsonVersionNumberConverter. Remove the header and source file from typeconverters.pri and remove the include and registration from the qjsonserializer.cpp file.

from qtjsonserializer.

useful-friend avatar useful-friend commented on July 20, 2024

Thanks for the complete clarification and your time.

from qtjsonserializer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.