- for (var childNode : candidate.getChildNodes()) {
- path.add(childNode.getIdentifier());
- ret |= serializeLeafNodesOnly(path, childNode, skipData, changedLeafNodesOnly);
- path.removeLast();
+ for (var childNode : candidate.childNodes()) {
+ final var childName = childNode.name();
+ if (myNamespace.equals(childName.getNodeType().getModule())) {
+ ret |= serializeChild(path, childNode, skipData, changedLeafNodesOnly);
+ } else {
+ heldBack.add(childNode);
+ }
+ }
+ if (!heldBack.isEmpty()) {
+ // This is not exactly nice, as we really should be using schema definition order, but we do not have it
+ // available here, so we fall back to the next best thing.
+ heldBack.sort(Comparator.comparing(DataTreeCandidateNode::name));
+ for (var childNode : heldBack) {
+ ret |= serializeChild(path, childNode, skipData, changedLeafNodesOnly);
+ }