title: JJWT / Jackson alter the ObjectMapper used
body: <p>For a project I am working on, I am required to use Spring Security and JSON Webtokens as provided by the library <a href="https://github.com/jwtk/jjwt" rel="nofollow noreferrer">io.jsonwebtoken (jjwt)</a>. One of the claims I am required to add to my generated token is the following entity (simplified to illustrate the problem):</p>
  
  <pre><code>@Entity
  public class MyEntity {
      private String name;
      private LocalDateTime ldt;
  }
  </code></pre>
  
  <p>This works, but the resulting webtoken is serialized as following:</p>
  
  <pre><code>{
    "sub": "testuser@mydomain.com",
    "exp": 1523659655,
    "entity": {
      "name": testname,
      "ldt": {
        "hour": 0,
        "minute": 37,
        "dayOfMonth": 12,
        "dayOfWeek": "THURSDAY",
        "dayOfYear": 102,
        "year": 2018,
        "month": "APRIL",
        "monthValue": 4,
        "second": 38,
        "nano": 569000000,
        "chronology": {
          "calendarType": "iso8601",
          "id": "ISO"
        }
      }
    }
  }
  </code></pre>
  
  <p>This might not seem like a problem, but it is in fact a problem when later on I am required to map it to an instance of MyEntity again. After some reading online I figured that I need to change the configuration of the ObjectMapper, to change the configuration options (toggle the <code>WRITE_DATES_AS_TIMESTAMPS</code>-flag to false). However, I cannot alter the configuration of the ObjectMapper used by jjwt as it's constructed like this (source of jjwt):</p>
  
  <pre><code>public class DefaultJwtBuilder implements JwtBuilder {
      private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
      ...
  }
  </code></pre>
  
  <p>Another option I found online was to put the following line in my application.properties file:</p>
  
  <pre><code>spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false
  </code></pre>
  
  <p>Yet to no avail, the ObjectMapper used by jjwt seems to ignore these properties.</p>
  
  <p>What would I do to accomplish my goal?</p>