Search in sources :

Example 1 with Field

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);
        }
    }
}
Also used : Field(com.developmentontheedge.be5.metadata.serialization.Field) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) WriteException(com.developmentontheedge.be5.metadata.exception.WriteException)

Aggregations

ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)1 WriteException (com.developmentontheedge.be5.metadata.exception.WriteException)1 Field (com.developmentontheedge.be5.metadata.serialization.Field)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1