@Override
public Data encodeForResolveField(final ObjectAdapter adapter, final String fieldName) {
final Oid oid = adapter.getOid();
final ObjectSpecification specification = adapter.getSpecification();
final String type = specification.getFullIdentifier();
final ResolveState resolveState = adapter.getResolveState();
Data[] fieldContent;
final ObjectAssociation[] fields = getFieldOrder(specification);
fieldContent = new Data[fields.length];
PersistorUtil.start(adapter, adapter.getResolveState().serializeFrom());
final KnownObjectsRequest knownObjects = new KnownObjectsRequest();
for (int i = 0; i < fields.length; i++) {
if (fields[i].getId().equals(fieldName)) {
final ObjectAdapter field = fields[i].get(adapter);
if (field == null) {
fieldContent[i] = dataFactory.createNullData(fields[i].getSpecification().getFullIdentifier());
} else if (fields[i].getSpecification().isEncodeable()) {
fieldContent[i] = serializer.serializeEncodeable(field);
} else if (fields[i].isOneToManyAssociation()) {
fieldContent[i] =
serializer.serializeCollection(field, serverSideRetrievedObjectGraphDepth, knownObjects);
} else {
IsisContext.getPersistenceSession().resolveImmediately(field);
fieldContent[i] =
serializer.serializeAdapter(field, serverSideRetrievedObjectGraphDepth, knownObjects);
}
break;
}
}
PersistorUtil.end(adapter);
// TODO remove the fudge - needed as collections are part of parents, hence parent object gets set as
// resolving (is not a ghost) yet it has no version number
// return createObjectData(oid, type, fieldContent, resolveState.isResolved(),
// !resolveState.isGhost(), object.getVersion());
final ObjectData data =
dataFactory.createObjectData(type, oid, resolveState.isResolved(), adapter.getVersion());
data.setFieldContent(fieldContent);
return data;
// return createObjectData(oid, type, fieldContent, resolveState.isResolved(), object.getVersion());
}