OLINGO-1009: refining the cycle detection logic

This commit is contained in:
Ramesh Reddy 2016-09-09 19:00:57 -05:00
parent 120adfea50
commit 591f9522b5
2 changed files with 8 additions and 10 deletions

View File

@ -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));
}
}

View File

@ -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));
}
}
}