Bug #12325
openDbo::jsonSerialize produces objects with empty names
0%
Description
When Dbo::belongsTo
is called with default empty string argument, when trying to serialize object I'm getting strings like this: {"""":null,"""":2,""count"":1}
If WT uses mapped table names for SQL queries, why not to use them for serialization?
Updated by Matthias Van Ceulebroeck 3 months ago
- Status changed from New to Feedback
- Assignee set to Andrey Alekseev
Hi Andrey,
I have set up a minimal example, where the Dbo has the following structure. I have abbreviated the classes to ensure that it's understandable.
class Item:
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, field_, "field");
Wt::Dbo::belongsTo(a, relatedItem1_, "related");
Wt::Dbo::belongsTo(a, relatedItem2_, "");
Wt::Dbo::belongsTo(a, relatedOtherItem_, "");
}
private:
std::string field_;
Wt::Dbo::ptr<Item> relatedItem1_;
Wt::Dbo::ptr<Item> relatedItem2_;
Wt::Dbo::ptr<OtherItem> relatedOtherItem_;
class OtherItem:
template<class Action>
oid persist(Action& a)
{
Wt::Dbo::field(a, field_, "field");
}
private:
std::string field_;
Both of these classes are mapped in the the session.
mapClass<Item>("item");
mapClass<OtherItem>("other_item");
I then set up a couple values like:
auto item = session_.addNew<Item>();
item.modify()->setField("value");
auto subitem1 = session_.addNew<Item>();
subitem1.modify()->setField("subvalue1");
item.modify()->setItem1(subitem1);
auto subitem2 = session_.addNew<Item>();
subitem2.modify()->setField("subvalue2");
item.modify()->setItem1(subitem2);
The output of serialization then gives:
std::stringstream output;
Wt::Dbo::jsonSerialize<Item>(item, output);
{""id"":2,""field"":""value"",""related"":1,""item"":null,""other_item"":null}
, which correctly uses the default mapped names of the tables.
I suspect there may be something different in your test set-up? Could you provide me with a minimal working example so I can see if there is an issue?