title: Decode base64 encoded JSON to POJO with jackson and spring-boot
body: <p>I have a request coming like this</p>
  
  <pre><code>{
      "varA"  : "A",
      "varB" : "TCFNhbiBKb3NlMRgwFgYDVQQK"
  }
  </code></pre>
  
  <p>where key <code>varB</code> is a base64 encoded JSON string. something like this:</p>
  
  <pre><code>{
      "nestedVarB1": "some value here",
      "nestedVarB2" : "some other value here"
  }
  </code></pre>
  
  <p>I want to convert it into some POJOs like this:</p>
  
  <pre><code>@Data
  public class MyRequest {
      private String varA;
      private B varB;
  }
  
  @Data
  public class B {
      private String nestedVarB1;
      private String nestedVarB2;
  }
  </code></pre>
  
  <p>I went through several solutions on stack overflow like <a href="https://stackoverflow.com/questions/13414890/decode-base64-with-jackson-or-spring">this</a> and <a href="https://stackoverflow.com/questions/39236936/base64-decode-then-deserialize-json-to-pojo-with-moshi">this</a>, but I want to convert the JSON directly into an object of type <code>MyRequest</code> maybe by writing some sort of Jackson deserializer.</p>
  
  <p>How can I convert the JSON directly into <code>MyRequest</code> using Jackson and Spring Boot?</p>
  
  <p>Note:</p>
  
  <ol>
  <li>POJOs <code>MyRequest</code> and <code>B</code> are very big and <code>B</code> could be further nested, so doing it manually would be a big task.</li>
  <li>I don't have any control over the request coming, it is coming from a third party source. So, can't change the format of the request.</li>
  </ol>