title: Jackson YAML: parsing anchors and references
body: <p>This is a follow-up question on <a href="https://stackoverflow.com/questions/40074700/jackson-yaml-support-for-anchors-and-references">Jackson YAML: support for anchors and references</a>:
  I had a tough time understanding how Jackson treats references (since they don't exist natively in JSON), so I wrote a test:</p>
  
  <pre><code>import com.fasterxml.jackson.databind.DeserializationFeature
  import com.fasterxml.jackson.databind.ObjectMapper
  import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
  import com.fasterxml.jackson.module.kotlin.KotlinModule
  import org.junit.Test
  import org.yaml.snakeyaml.Yaml
  import kotlin.test.assertEquals
  
  class YamlRefTest {
      data class Item(val name: String)
      data class Config(val availableItems: List&lt;Item&gt;, 
                        val selectedItems: List&lt;Item&gt;)
  
      @Test
      fun testReferenceSnakeYaml() {
          val parser = Yaml()
  
          val test = (parser.load(testYaml) 
            as Map&lt;String, Map&lt;String, List&lt;Map&lt;String, String&gt;&gt;&gt;&gt;)["Config"]!!
          assertEquals("test", test["availableItems"]!![0]["name"])
          assertEquals("test", test["selectedItems"]!![0]["name"])
      }
  
      @Test
      fun testReferenceJackson() {
          val mapper = ObjectMapper(YAMLFactory())
                  .registerModule(KotlinModule())
                  .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true)
  
          val config = mapper.readValue(testYaml, Config::class.java)
  
          assertEquals(1, config.selectedItems.size)
          assertEquals("test", config.selectedItems[0].name)
      }
  
      companion object {
          val testYaml = """
  Config:
      availableItems:
        - &amp;a1
          name: test
        - &amp;a2
          name: test2
      selectedItems:
        - *a1
          """
      }
  }
  </code></pre>
  
  <p>The first test passes, the second doesn't. From my understanding of the spec, if you just use anchors (without the merge syntax), YAML treats references pretty much as copy and paste. Why isn't this possible with Jackson? And if it is, what do I need to do to make this work?</p>
  
  <p>This currently fails with:</p>
  
  <pre><code>com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `undagen.YamlRefTest$Item` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('a1')
   at [Source: (StringReader); line: 9, column: 9] (through reference chain: undagen.YamlRefTest$Config["selectedItems"]-&gt;java.util.ArrayList[0])
  </code></pre>
  
  <p><em>Note:</em> Answers involving the correct use of <code>@JsonIdentityInfo</code> are helpful (I can't seem to grok how this translates to anchors).</p>