title: Spring HATEOAS Jackson2HalModule
body: <p>Suppose I do not wish to use <code>ResourceSupport</code> from <code>spring hateoas</code>, but I still want to use <code>Link</code>.</p>
  
  <p>Basic setup:</p>
  
  <pre><code>class A extends ResourceSupport {
  
  }
  
  public class B {
  
      private final List&lt;Link&gt; links = new ArrayList&lt;&gt;();
  
      @JsonProperty("links")
      public List&lt;Link&gt; getLinks() {
          return links;
      }
  }
  </code></pre>
  
  <p>http methods:</p>
  
  <pre><code>@GetMapping('/a')
  ResponseEntity&lt;A&gt; a() {
      A a = new A()
  
      a.getLinks().add(new Link('/api', 'index'))
      return ok(a)
  }
  
  @GetMapping('/b')
  ResponseEntity&lt;B&gt; b() {
      B ab= new B()
  
      abgetLinks().add(new Link('/api', 'index'))
      return ok(b)
  }
  </code></pre>
  
  <p>Jackson config:</p>
  
  <pre><code>@Primary
  @Bean
  Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder(RelProvider relProvider, ApplicationContext applicationContext) {
      Jackson2HalModule.HalHandlerInstantiator halHandlerInstantiator = new Jackson2HalModule.HalHandlerInstantiator(
          relProvider, null, new MessageSourceAccessor(applicationContext), false
      )
  
      JavaTimeModule javaTimeModule = new JavaTimeModule()
      javaTimeModule.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer(isoDateFormatter()))
  
      return Jackson2ObjectMapperBuilder.json()
          .handlerInstantiator(halHandlerInstantiator)
          .modules(
              new Jdk8Module(),
              new JavaTimeModule(),
              new ParameterNamesModule(JsonCreator.Mode.PROPERTIES),
              new Jackson2HalModule()
          )
          .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
          .featuresToEnable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN)
  }
  </code></pre>
  
  <p>And response from <code>a</code> and <code>b</code> respectively:</p>
  
  <pre><code>http://localhost:8080/api/a
  {
    "_links": {
      "index": {
        "href": "/api"
      }
    }
  }
  
  http://localhost:8080/api/b
  {
    "links": [
      {
        "href": "/api"
      }
    ]
  }
  </code></pre>
  
  <p>the <code>/a</code> response is perfect! Why doesn't <code>Jackson2HalModule</code> pick up the <code>spring-hateoas</code> <code>Link</code> list without resource support?
  I tried a bit of debugging but got confused by how Jackson internally decides when to use <code>HalLinkListDeserializer</code> and when not to.</p>