title: Different types JSON file using ObjectMapper
body: <p>I am using AlamofireObjectMapper to communicate with a backend server. The result of one of the requests is an array of items, which contain two values:</p>
  
  <ul>
  <li>A "typeIdentifier" indicating which type of data the second value ("arbitraryData") is of</li>
  <li>A "arbitraryData": 
  
  <ul>
  <li>If "typeIdentifier" CONTAINS "X", arbitraryData is of type ArbitraryDataTypeX</li>
  <li>If "typeIdentifier" CONTAINS "Y", arbitraryData is of type ArbitraryDataTypeY</li>
  </ul></li>
  </ul>
  
  <p>The two ArbitraryDataType classes do not share any common ancestor (except Mappable). It could be even a primitive type, an array, an optional, etc.</p>
  
  <p>How can I make AlamofireObjectMapper parse the "arbitraryData" field using the appropriate type.</p>
  
  <p>See the following JSON file:</p>
  
  <pre><code>{
      "arrayOfItems": [
          {
              "typeIdentifier": "X",
              "arbitraryData":
                  {
                      "value": "BLA",
                  }
          },
          {
              "typeIdentifier": "Y",
              "arbitraryData":
                  {
                      "anotherValue": "BLUBB",
                  }
          }
      ]
  }
  </code></pre>
  
  <p>My corresponding Swing file looks like the following:</p>
  
  <pre><code>class Item : Mapping {
      var typeIdentifier = "X"
      var arbitraryData: Mappable? = nil
  
      init?(_ map: Map) {
          self.init()
          mapping(map)
      }
  
      func mapping(map: Map) {
          typeIdentifier &lt;- map["typeIdentifier"]
  
          // THIS LINE CONTAINS MY QUESTION: HOW CAN I TELL OBJECTMAPPER, THAT,
          // IF typeIdentifier CONTAINS "X", arbitraryData IS OF TYPE
          // ArbitraryDataTypeX, AND IF "Y" arbitraryData IS OF TYPE
          // ArbitraryDataTypeY?
          arbitraryData &lt;- map["arbitraryData"]
      }
  }
  
  class ArbitraryDataTypeX : Mapping {
      var value = "BLA"
  
      init?(_ map: Map) {
          self.init()
          mapping(map)
      }
  
      func mapping(map: Map) {
          value &lt;- map["value"]
      }
  }
  
  class ArbitraryDataTypeY : Mapping {
      var anotherValue = "BLUBB"
  
      init?(_ map: Map) {
          self.init()
          mapping(map)
      }
  
      func mapping(map: Map) {
          anotherValue &lt;- map["anotherValue"]
      }
  }
  </code></pre>
  
  <p>Background information: I am using AlamofireObjectMapper to communicate with a backend server. The result of one of the requests is an array of Item. The typeIdentifier-mechanism (infact it is a little bit more complex, but let's leave this out) is given by the backend and cannot be changed.</p>