java.lang.Object
de.hybris.platform.servicelayer.internal.converter.util.ModelUtils

public final class ModelUtils extends Object
This class contains some utility methods for getting/setting field values and check for methods/field. These methods are based on reflection.
  • Method Details

    • getFieldValue

      public static Object getFieldValue(Object model, String field)
      Returns the value of the field (given by the field name) from the given model. per reflection. Searches all superclasses of the model.
      Parameters:
      model - the model
      field - the field name
      Returns:
      null if not such field at the model exists, otherwise the value object is returned
      Throws:
      IllegalStateException - if an unexpected reflection exception occurs.
    • setFieldValue

      public static boolean setFieldValue(Object model, String field, Object value)
      Sets in the given model the given value into the field by the given field name per reflection and returns true if this was successful.
      Parameters:
      model - the model where the value should be set
      field - the field name at the model
      value - the value to be set
      Returns:
      false if no such fiel at the model was found
    • isPrimitiveField

      public static boolean isPrimitiveField(Class model, String field)
      Returns (per reflection) true if in the class the field by it's given field name is a primitive type.
      Parameters:
      model - the class model
      field - the field name
      Returns:
      false if the field is not primitive or the field doesn't exist in the class
    • getFieldType

      public static Class getFieldType(Class model, String field)
      Returns a Class object that identifies the declared type for the given field name of the given model class.
      Parameters:
      model - the model class
      field - the field name
      Returns:
      null if no such field was found, otherwise the type class is returned
    • existsMethod

      public static boolean existsMethod(Class model, String method)
      Returns true if in the given class model a method by the given method name exists. The method can have any signature.
      Parameters:
      model - the class model
      method - the method name
      Returns:
      false if no such method exists in the given class model
    • existsField

      public static boolean existsField(Class model, String field)
      Returns true if in the given class model a field by the given fieldname exists. Searches all superclasses of the given class model.
      Parameters:
      model - the class model
      field - the fieldname
      Returns:
      false if no such field exists in the given class model
    • enumEquals

      public static boolean enumEquals(HybrisEnumValue enum1, Object obj)
      Compares enum object with another object. Used inside generated dynamic enum values.
      Parameters:
      enum1 - the first enum
      obj - the second enum
      Returns:
      true if both objects are dynamic enum values and have the same type and code; please note that type and code are case insensitive!