title: Extending spring-hateoas Link class after constructor deprecation
body: <p>In my application I have class that extends spring-hateoas <code>Link</code> class:</p>
  <pre><code>class LinkWithAdditionalField extends Link {
      private final String additionalField;
  
      LinkWithAdditionalField(String href, String rel, String additionalField) {
          super(href, rel);
          this.additionalField = additionalField;
      }
  
      ...
  }
  </code></pre>
  <p>that adds additional field to model representation:</p>
  <pre><code>&quot;_links&quot; : {
      &quot;self&quot; : {
          &quot;href&quot;: &quot;https://example.com/...&quot;,
          &quot;additionalField&quot;: &quot;additionalValue&quot;
      }
  }
  </code></pre>
  <p>and it is used this way:</p>
  <pre><code>LinkWithAdditionalField link = (LinkWithAdditionalField) entityModel.getLinks().toList().get(index)
  String additionalField = link.getAdditionalField();
  </code></pre>
  <p>It is working, however version <code>1.1</code> of spring-hateoas deprecated <a href="https://docs.spring.io/spring-hateoas/docs/current/api/org/springframework/hateoas/Link.html" rel="nofollow noreferrer"><code>Link(String, String)</code></a> constructor (and recommends using static method <code>Link.of(String, String)</code>) .</p>
  <p>Is there any recommended way (some new API that I am missing?) to do this, that allows adding additional fields to links, after upgrading Spring to latest version?</p>
  <p>Using composition (and static method <code>Link.of(String, String)</code>):</p>
  <pre><code>class LinkWithAdditionalField {
      private final Link link;
      private final String additionalField;
  
      LinkWithAdditionalField(String href, String rel, String additionalField) {
          this.link = Link.of(href, rel);
          this.additionalField = additionalField;
      }
  
      ...
  }
  </code></pre>
  <p>won't work in my case because of casting:</p>
  <pre><code>LinkWithAdditionalField link = (LinkWithAdditionalField) entityModel.getLinks().toList().get(index)
  </code></pre>