final PropertyMode propertyMode, final boolean succinct, final DateTimeFormat dateTimeFormat) {
if (object == null) {
return null;
}
JSONObject result = new JSONObject();
// properties
if (object.getProperties() != null) {
if (succinct) {
JSONObject properties = convert(object.getProperties(), object.getId(), typeCache, propertyMode, true,
dateTimeFormat);
if (properties != null) {
result.put(JSON_OBJECT_SUCCINCT_PROPERTIES, properties);
}
} else {
JSONObject properties = convert(object.getProperties(), object.getId(), typeCache, propertyMode, false,
dateTimeFormat);
if (properties != null) {
result.put(JSON_OBJECT_PROPERTIES, properties);
}
}
JSONObject propertiesExtension = new JSONObject();
convertExtension(object.getProperties(), propertiesExtension);
if (!propertiesExtension.isEmpty()) {
result.put(JSON_OBJECT_PROPERTIES_EXTENSION, propertiesExtension);
}
}
// allowable actions
if (object.getAllowableActions() != null) {
result.put(JSON_OBJECT_ALLOWABLE_ACTIONS, convert(object.getAllowableActions()));
}
// relationships
if (isNotEmpty(object.getRelationships())) {
JSONArray relationships = new JSONArray();
for (ObjectData relationship : object.getRelationships()) {
relationships.add(convert(relationship, typeCache, propertyMode, succinct, dateTimeFormat));
}
result.put(JSON_OBJECT_RELATIONSHIPS, relationships);
}
// change event info
if (object.getChangeEventInfo() != null && propertyMode == PropertyMode.CHANGE) {
JSONObject changeEventInfo = new JSONObject();
ChangeEventInfo cei = object.getChangeEventInfo();
changeEventInfo.put(JSON_CHANGE_EVENT_TYPE, getJSONEnumValue(cei.getChangeType()));
changeEventInfo.put(JSON_CHANGE_EVENT_TIME, getJSONValue(cei.getChangeTime(), dateTimeFormat));
convertExtension(object.getChangeEventInfo(), changeEventInfo);
result.put(JSON_OBJECT_CHANGE_EVENT_INFO, changeEventInfo);
}
// ACL
if ((object.getAcl() != null) && (object.getAcl().getAces() != null) && propertyMode != PropertyMode.QUERY) {
result.put(JSON_OBJECT_ACL, convert(object.getAcl()));
}
setIfNotNull(JSON_OBJECT_EXACT_ACL, object.isExactAcl(), result);
// policy ids
if ((object.getPolicyIds() != null) && (object.getPolicyIds().getPolicyIds() != null)
&& propertyMode != PropertyMode.QUERY) {
JSONObject policyIds = new JSONObject();
JSONArray ids = new JSONArray();
policyIds.put(JSON_OBJECT_POLICY_IDS_IDS, ids);
for (String pi : object.getPolicyIds().getPolicyIds()) {
ids.add(pi);
}