@@ -0,0 +1,2117 @@
+package at.rags.morpheus;%0A%0Aimport android.util.ArrayMap;%0Aimport android.util.Log;%0A%0Aimport com.google.gson.annotations.SerializedName;%0A%0Aimport java.lang.annotation.Annotation;%0Aimport java.lang.reflect.Field;%0Aimport java.util.ArrayList;%0Aimport java.util.Dictionary;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Objects;%0A%0Aimport at.rags.morpheus.Annotations.Relationship;%0A%0A/**%0A */%0Apublic class Serializer %7B%0A%0A  /**%0A   * Return objects fields as dictionary with fieldName as key%0A   * and fieldObject as value.%0A   *%0A   * @param resource A morpheus resource.%0A   * @return hashMap of field names and values.%0A   */%0A  public HashMap%3CString, Object%3E getFieldsAsDictionary(Resource resource) %7B%0A    HashMap%3CString, Object%3E fieldDict = new HashMap%3C%3E();%0A%0A    for (Field field : resource.getClass().getDeclaredFields()) %7B%0A      String fieldName = null;%0A%0A      if (field.isAnnotationPresent(Relationship.class)) %7B%0A        continue;%0A      %7D%0A%0A      if (field.isAnnotationPresent(SerializedName.class)) %7B%0A        Annotation annotation = field.getAnnotation(SerializedName.class);%0A        SerializedName serializeName = (SerializedName) annotation;%0A        fieldName = serializeName.value();%0A      %7D else %7B%0A        fieldName = field.getName();%0A      %7D%0A%0A      try %7B%0A        field.setAccessible(true);%0A        fieldDict.put(fieldName, field.get(resource));%0A      %7D catch (IllegalAccessException e) %7B%0A        e.printStackTrace();%0A      %7D%0A    %7D%0A%0A    return fieldDict;%0A  %7D%0A%0A  public HashMap%3CString, Object%3E getRelationships(Resource resource) %7B%0A    HashMap%3CString, Object%3E relationships = new HashMap%3C%3E();%0A%0A    for (Field field : resource.getClass().getDeclaredFields()) %7B%0A      if (field.isAnnotationPresent(Relationship.class)) %7B%0A        Annotation annotation = field.getAnnotation(Relationship.class);%0A        Relationship relationship = (Relationship) annotation;%0A%0A        field.setAccessible(true);%0A        try %7B%0A          relationships.put(relationship.value(), field.get(resource));%0A        %7D catch (IllegalAccessException e) %7B%0A          e.printStackTrace();%0A        %7D%0A      %7D%0A    %7D%0A%0A    return relationships;%0A  %7D%0A%7D%0A

Add Serializer