Fix serialization of node ids, closes #3958.