fix(serialize-xml): custom path generation
This commit is contained in:
parent
de55636d20
commit
b8d9b52ab5
|
@ -369,14 +369,41 @@ public class XmlReader extends SerializeReader<IOException, XmlReader> implement
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getPath(boolean usePreviousPath) {
|
||||||
|
if (nextTagNamePath != null) return nextTagNamePath;
|
||||||
|
StringBuilder result = new StringBuilder().append('$');
|
||||||
|
for (int i = 0; i < stackSize; i++) {
|
||||||
|
int scope = stack[i];
|
||||||
|
switch (scope) {
|
||||||
|
case WrapperScope.ARRAY -> {
|
||||||
|
int pathIndex = pathIndices[i];
|
||||||
|
// If index is last path element it points to next array element; have to decrement
|
||||||
|
if (usePreviousPath && pathIndex > 0 && i == stackSize - 1) {
|
||||||
|
pathIndex--;
|
||||||
|
}
|
||||||
|
result.append('[').append(pathIndex).append(']');
|
||||||
|
}
|
||||||
|
case WrapperScope.OBJECT -> {
|
||||||
|
result.append('.');
|
||||||
|
if (pathNames[i] != null) {
|
||||||
|
result.append(pathNames[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case WrapperScope.OBJECT_VALUE_WRAPPER, WrapperScope.OBJECT_VALUE_WRAPPER_USED, WrapperScope.DOCUMENT -> {}
|
||||||
|
default -> throw new AssertionError("Unknown scope value: " + scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return nextTagName == null ? reader.getPath() : nextTagNamePath;
|
return getPath(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreviousPath() {
|
public String getPreviousPath() {
|
||||||
return getPath(); // TODO this should be different when handling arrays
|
return getPath(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user