public static JSONObject convert(PropertyData<?> property, PropertyDefinition<?> propDef) {
if (property == null) {
return null;
}
JSONObject result = new JSONObject();
result.put(JSON_PROPERTY_ID, property.getId());
setIfNotNull(JSON_PROPERTY_LOCALNAME, property.getLocalName(), result);
setIfNotNull(JSON_PROPERTY_DISPLAYNAME, property.getDisplayName(), result);
setIfNotNull(JSON_PROPERTY_QUERYNAME, property.getQueryName(), result);
if (propDef != null) {
result.put(JSON_PROPERTY_DATATYPE, propDef.getPropertyType().value());
result.put(JSON_PROPERTY_CARDINALITY, propDef.getCardinality().value());
if ((property.getValues() == null) || (property.getValues().size() == 0)) {
result.put(JSON_PROPERTY_VALUE, null);
} else if (propDef.getCardinality() == Cardinality.SINGLE) {
result.put(JSON_PROPERTY_VALUE, getJSONValue(property.getValues().get(0)));
} else {
JSONArray values = new JSONArray();
for (Object value : property.getValues()) {
values.add(getJSONValue(value));
}
result.put(JSON_PROPERTY_VALUE, values);
}
} else {
result.put(JSON_PROPERTY_DATATYPE, getJSONPropertyDataType(property));
if ((property.getValues() == null) || (property.getValues().size() == 0)) {
result.put(JSON_PROPERTY_VALUE, null);
} else if (property.getValues().size() > 0) {
JSONArray values = new JSONArray();
for (Object value : property.getValues()) {
values.add(getJSONValue(value));
}
result.put(JSON_PROPERTY_VALUE, values);
}
}
convertExtension(property, result);