Enforce tree order in JSON. (#5974)

* Make JSON model IO more future proof by using tree id in model loading.
This commit is contained in:
Jiaming Yuan
2020-08-05 16:44:52 +08:00
committed by GitHub
parent dde9c5aaff
commit 9c6e791e64
2 changed files with 23 additions and 12 deletions

View File

@@ -148,7 +148,16 @@ TEST(Learner, JsonModelIO) {
Json out { Object() };
learner->SaveModel(&out);
learner->LoadModel(out);
dmlc::TemporaryDirectory tmpdir;
std::ofstream fout (tmpdir.path + "/model.json");
fout << out;
fout.close();
auto loaded_str = common::LoadSequentialFile(tmpdir.path + "/model.json");
Json loaded = Json::Load(StringView{loaded_str.c_str(), loaded_str.size()});
learner->LoadModel(loaded);
learner->Configure();
Json new_in { Object() };