in lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java [542:598]
protected void writeNavigationProperties(final ServiceMetadata metadata,
final EdmStructuredType type, final Linked linked, final ExpandOption expand, final Integer toDepth,
final Set<String> ancestors, final String name, final JsonGenerator json)
throws SerializerException, IOException, DecoderException {
if (isODataMetadataFull) {
for (final String propertyName : type.getNavigationPropertyNames()) {
final Link navigationLink = linked.getNavigationLink(propertyName);
if (navigationLink != null) {
json.writeStringField(propertyName + constants.getNavigationLink(), navigationLink.getHref());
}
final Link associationLink = linked.getAssociationLink(propertyName);
if (associationLink != null) {
json.writeStringField(propertyName + constants.getAssociationLink(), associationLink.getHref());
}
}
}
if ((toDepth != null && toDepth > 1) || (toDepth == null && ExpandSelectHelper.hasExpand(expand))) {
final ExpandItem expandAll = ExpandSelectHelper.getExpandAll(expand);
for (final String propertyName : type.getNavigationPropertyNames()) {
final ExpandItem innerOptions = ExpandSelectHelper.getExpandItemBasedOnType(expand.getExpandItems(),
propertyName, type, name);
if (innerOptions != null || expandAll != null || toDepth != null) {
Integer levels = null;
final EdmNavigationProperty property = type.getNavigationProperty(propertyName);
final Link navigationLink = linked.getNavigationLink(property.getName());
ExpandOption childExpand = null;
LevelsExpandOption levelsOption = null;
if (innerOptions != null) {
levelsOption = innerOptions.getLevelsOption();
childExpand = levelsOption == null ? innerOptions.getExpandOption() : new ExpandOptionImpl().addExpandItem(
innerOptions);
} else if (expandAll != null) {
levels = 1;
levelsOption = expandAll.getLevelsOption();
childExpand = new ExpandOptionImpl().addExpandItem(expandAll);
}
if (levelsOption != null) {
levels = levelsOption.isMax() ? Integer.MAX_VALUE : levelsOption.getValue();
}
if (toDepth != null) {
levels = toDepth - 1;
childExpand = expand;
}
writeExpandedNavigationProperty(metadata, property, navigationLink,
childExpand, levels,
innerOptions == null ? null : innerOptions.getSelectOption(),
innerOptions == null ? null : innerOptions.getCountOption(),
innerOptions == null ? false : innerOptions.hasCountPath(),
innerOptions == null ? false : innerOptions.isRef(),
ancestors, name,
json);
}
}
}
}