Class PropertyMapping

    • Constructor Detail

      • PropertyMapping

        public PropertyMapping()
    • Method Detail

      • mapValue

        public PropertyMapping mapValue​(String from,
                                        String to)
        Maps the source's property to the destination's property. Useful for mapping a property, for example:
         // mapValue("state", "region");
         { state: "TX" } => { region: "TX" }
         
        Parameters:
        from - the source property
        to - the destination property
        Returns:
        the mapping
      • mapValue

        public PropertyMapping mapValue​(String from,
                                        String to,
                                        @Nullable
                                        Object defaultValue)
        Maps the source's property to the destination's property with a default value. Useful for when you need a useful default, for example:
         // mapValue("state", "region", "N/A");
         { city: "Washington" } => { city: "Washington", region: "N/A" }
         
        Parameters:
        from - the source property
        to - the destination property
        defaultValue - the default value
        Returns:
        the mapping
      • mapValueToRoot

        public PropertyMapping mapValueToRoot​(String from)
        Maps the source's property to the ROOT. Useful for reducing an object down to one of its properties, for example:
         // mapValueToRoot("label")
         { label: "RED" } => "RED"
         
        Parameters:
        from - the source property
        Returns:
        the mapping
      • mapValueFromRoot

        public PropertyMapping mapValueFromRoot​(String to)
        Maps the ROOT to the destination. Useful for mapping an object to a property of a new object.
         // mapValueFromRoot("details")
         { label: "RED" } => { details: { label: "RED" } }
         
        Parameters:
        to - the destination property
        Returns:
        the mapping
      • setValue

        public PropertyMapping setValue​(String to,
                                        @Nullable
                                        Object defaultValue)
        Sets the value on the destination. Useful for defaulting the value of a property, for example:
         // setValue("state", "TX");
         { city: "Austin" } => { city: "Austin", state: "TX" }
         
        Parameters:
        to - the destination property
        defaultValue - the default value of the property
        Returns:
        the mapping
      • nullValue

        public PropertyMapping nullValue​(String to)
        Sets the destination property to null. Useful for clearing out a value, for example:
         // nullValue("state");
         { state: "TX" } => { state: null }
         
        Parameters:
        to - the destination property
        Returns:
        the mapping
      • copyValue

        public PropertyMapping copyValue​(String from,
                                         String to)
        Copies the source property and maps to the destination property. Useful for mapping a property while preserving the original value, for example:
         // copyValue("state", "region");
         { state: "TX" } => { state: "TX", region: "TX" }
         
        Parameters:
        from - the source property
        to - the destination property
        Returns:
        the mapping
      • copyValue

        public PropertyMapping copyValue​(String from,
                                         String to,
                                         @Nullable
                                         Object defaultValue)
        Copies the source property and maps to the destination property. Useful for when you need a useful default, for example:
         // copyValue("state", "region", "TX");
         { } => { region: "TX" }
         
        Parameters:
        from - the source property
        to - the destination property
        defaultValue - the default value
        Returns:
        the mapping
      • getFrom

        public String getFrom()
        The name of the property to rename
      • getTo

        public String getTo()
        The new name of the property. This can not be null or empty If this is equals to ROOT then all properties from from will be mapped to the root object.
      • getOperation

        public String getOperation()
        The type of operation applied when mapping the property.
      • getValue

        public Object getValue()
        The new value of the property with name to This is ignored if from is defined
      • isCopy

        public boolean isCopy()
        Whether or not the property is copied. If false, the original property will be omitted.