Skip to content

Implicit Conversions

Alessandro Vurro edited this page Oct 5, 2016 · 4 revisions

JMapper allows to perform implicitly mapping between primitive and / or wrapper types, structures, mapped and target objects.
Below are represented the conventions used to handle all those conversions that are uncommon:

Conversion Result
Boolean -> Number 1 if Boolean is true, 0 if false
Boolean -> Character/char T if Boolean is true, F if false
String -> Character/char is taken the first character
Number -> boolean false if Number is equal to 0, true all other cases
Character/char -> Boolean true if Char is equal to T, false if Char is equal to F, null all other cases
Character/char -> boolean true if Char is equal to T, false all other cases

JMapper converts the arrays, collections and maps including their objects, for example (<--> means bidirectional):

  • from interface to implementation and vice versa
    List <--> ArrayList MyInterface <--> MyImplementation
  • between different interfaces
    List <--> Set
    Map <--> SortedMap
  • between different implementations
    ArrayList <--> HashSet
    HashMap <--> TreeMap
  • a combination of the two previous
    List <--> HashSet
    HashMap <--> SortedMap
  • conversion of primitive/wrapper items
    List<String> <--> HashSet<Integer>
    HashMap<Integer, String> <--> SortedMap<String, Integer>
  • conversion of mapped items
    List<TargetObj> <--> HashSet<ConfigObj>
    HashMap<Integer, ConfigObj> <--> SortedMap<String, TargetObj>
  • conversion of primitive/wrapper arrays
    String[] <--> Integer[]
  • conversion of mapped arrays
    TargetObj[] <--> ConfigObj[]
  • conversion between arrays and collections:
    • structural
      String[] <--> List<String>
    • with different primitive/wrapper types
      String[] <--> List<Integer>
    • with configured items
      TargetObj[] <--> List<ConfigObj>

Other conversions:

  • String <-> StringBuilder
  • String <-> StringBuffer
  • String <-> Enum
  • Date <-> Calendar
Clone this wiki locally