use of com.developmentontheedge.be5.metadata.serialization.Field in project be5 by DevelopmentOnTheEdge.
the class YamlSerializer method serializeFields.
static void serializeFields(final BeModelElement model, final List<Field> fields, final Map<String, Object> target) {
final Collection<String> inheritedProperties;
final Collection<String> customizedProperties;
inheritedProperties = new HashSet<>(model.getCustomizableProperties());
customizedProperties = model.getCustomizedProperties();
inheritedProperties.removeAll(customizedProperties);
for (final Field field : fields) {
// Remove 'name' field.
if (inheritedProperties.contains(field.name) || field.name.equals(ATTR_NAME))
continue;
try {
final Object fieldValue = Beans.getBeanPropertyValue(model, field.name);
if (fieldValue != null && (!fieldValue.equals(field.defaultValue) || customizedProperties.contains(field.name))) {
if (fieldValue instanceof Integer || fieldValue instanceof Boolean || fieldValue instanceof String)
target.put(field.name, fieldValue);
else
target.put(field.name, String.valueOf(fieldValue));
}
} catch (final Exception e) {
throw new RuntimeException("Unexpected error when serializing '" + field.name + "' of " + model.getCompletePath(), e);
}
}
}
Aggregations