Loki-Astari / ThorsMongo

C++ MongoDB API and BSON/JSON Serialization library
GNU General Public License v3.0
316 stars 71 forks source link

Is "__type" not required to be the first property anymore? #47

Closed ghost closed 5 years ago

ghost commented 5 years ago

The documentation states that "__type" has to be the first property when polymorphic types are used: https://github.com/Loki-Astari/ThorsSerializer/blob/master/doc/full.md#example-3-see-docexample3cpp

I noticed that a partner using the REST webservice we provide uses a JSON client that automatically sorts members and it thinks "__type" should be sorted as "type". Thus, it does not appear as the first property of the JSON anymore. But there is no exception from ThorsSerializer.

Is it not required any more that it has to be the first property?

Loki-Astari commented 5 years ago

I just tried this.
My tests generate an exception when deserializing polymorphic objects and the '__type' is not the first key in the object.

Can you provide a simple test that reproduces the problem.

Note: If the type is not polymorphic. Then having '__type' as one of the keys will be ignored unless you specify the ParserInterface::ParseType::Strict in the constructor for Parser you are using.

Loki-Astari commented 5 years ago

Closing issue as it seems to work correctly in the tests. OP has not provided a specific use case that causes failure.

ghost commented 5 years ago

I am also not able to reproduce it. In case it happens again. I will prepare an example.