Skip to content

PrintUtil fails with multi-valued attributes #276

@sdybiec

Description

@sdybiec

In class 'org.eclipse.emfcloud.modelserver.example.util.PrintUtil.java', the default case in the switch statement needs to account for the case of multi-valued attributes. The current code assumes all attributes are single-valued and fails with a ClassCastException when it encounters a multi-valued attribute. Here's the updated method that I used to fix the problem:

`@Override
public StringBuilder defaultCase(final EObject object) {
beginObject(object.eClass().getName() + " {");

     for (EAttribute attr : object.eClass().getEAllAttributes()) {
        Object value = object.eGet(attr);
        if (value instanceof List) {
           List<?> list = (List<?>) value;
           if (!list.isEmpty()) {
              for (Object oneValue : list) {
                 print(String.format("%s: %s", attr.getName(),
                    EcoreUtil.convertToString(attr.getEAttributeType(), oneValue)));
              }
           }
        } else {
           print(String.format("%s: %s", attr.getName(),
              EcoreUtil.convertToString(attr.getEAttributeType(), object.eGet(attr))));
        }

     }

     recurse(object);

     endObject("}");

     return result;
  }`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmodelserverEMF.cloud Model Server

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions