OLINGO-1009: refining the cycle detection logic
This commit is contained in:
parent
120adfea50
commit
591f9522b5
|
@ -323,13 +323,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
|
|||
final SelectOption select, final boolean onlyReference, Set<String> ancestors, final JsonGenerator json)
|
||||
throws IOException, SerializerException {
|
||||
boolean cycle = false;
|
||||
if (expand != null && cycleDetected(ancestors, getEntityId(entity))) {
|
||||
cycle = true;
|
||||
} else {
|
||||
if (expand != null) {
|
||||
if (ancestors == null) {
|
||||
ancestors = new HashSet<String>();
|
||||
}
|
||||
ancestors.add(getEntityId(entity));
|
||||
cycle = !ancestors.add(getEntityId(entity));
|
||||
}
|
||||
try {
|
||||
json.writeStartObject();
|
||||
|
@ -383,7 +381,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
|
|||
}
|
||||
json.writeEndObject();
|
||||
} finally {
|
||||
if (!cycle && ancestors != null) {
|
||||
if (expand != null && !cycle && ancestors != null) {
|
||||
ancestors.remove(getEntityId(entity));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -440,13 +440,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
final XMLStreamWriter writer, final boolean top, final boolean writeOnlyRef, Set<String> ancestors)
|
||||
throws XMLStreamException, SerializerException {
|
||||
boolean cycle = false;
|
||||
if (expand != null && cycleDetected(ancestors, getEntityId(entity))) {
|
||||
cycle = true;
|
||||
} else {
|
||||
if (expand != null) {
|
||||
if (ancestors == null) {
|
||||
ancestors = new HashSet<String>();
|
||||
}
|
||||
ancestors.add(getEntityId(entity));
|
||||
cycle = !ancestors.add(getEntityId(entity));
|
||||
}
|
||||
|
||||
if (cycle || writeOnlyRef) {
|
||||
|
@ -531,7 +529,9 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
|
||||
writer.writeEndElement(); // entry
|
||||
} finally {
|
||||
ancestors.remove(getEntityId(entity));
|
||||
if (!cycle && ancestors != null) {
|
||||
ancestors.remove(getEntityId(entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue