Serialization: Correctly encode structs with no fields
Empty structs were being serialized as `null`, when they should have been serialized as `{}`.
This was due to the type inference on the serializer - where no calls to `field()` would result in the default `null` type.
To solve this, the `serialize(const void* object, const std::initializer_list<Field>&)` inline helper has been promoted to a virtual function (and renamed to `fields()`).
The JSON serializer implementation of this now first sets the object type to `object`, even if there are no fields to serialize.
Added test for this.
Fixes: #10
This commit is contained in:
@@ -164,7 +164,7 @@ M member_type(M T::*);
|
||||
return d->deserialize(ptr, {__VA_ARGS__}); \
|
||||
} \
|
||||
bool serialize(Serializer* s, const void* ptr) const override { \
|
||||
return s->serialize(ptr, {__VA_ARGS__}); \
|
||||
return s->fields(ptr, {__VA_ARGS__}); \
|
||||
} \
|
||||
}; \
|
||||
static TI typeinfo; \
|
||||
|
||||
Reference in New Issue
Block a user