title: How to inject the whole root json object into a POJO property in Jackson?
body: <pre><code>class MyModel{
  
      @JsonProperty(&quot;first&quot;)
      public int a; 
  
      @JsonProperty(&quot; ??? &quot;)
      public String originalJson;
  } 
  
  void test(){
      var payload = &quot;&quot;&quot; [
            {&quot;a&quot;: 1, &quot;b&quot;: &quot;xxx&quot;},
            {&quot;a&quot;: 2, &quot;b&quot;: &quot;yyy&quot;, &quot;c&quot;: [1,2,3,4]}
      ]
      &quot;&quot;&quot;;
  
      MyModel[] models = new ObjectMapper().readValue(payload, MyModel[].class);
  
      assertEquals(&quot;&quot;&quot;{&quot;a&quot;: 1, &quot;b&quot;: &quot;xxx&quot;}&quot;&quot;&quot;, model[0].originalJson);
  
      assertEquals(&quot;&quot;&quot;{&quot;a&quot;: 2, &quot;b&quot;: &quot;yyy&quot;, &quot;c&quot;: [1,2,3,4]}&quot;&quot;&quot;, model[1].originalJson);
  }
  </code></pre>
  <p>I'm looking for a standard approach of putting original JSON part (as String or as JsonNode) into a particular property of the model object. Cannot find anything similar, because all annotations can address only contained property names/paths, but not the whole JSON object.</p>
  <p>The closest thing I've found is a custom deserialiser, but still it's not clear how to use it in this case.</p>
  <pre><code>class MyModel{
  
      // not clear how to pass the whole object here, not a single field
  
      @JsonProperty(&quot; ??? &quot;)
      @JsonDeserialize(using = SampleDeserializer.class)
      public String originalJson;
  } 
  
  
  public static class SampleDeserializer extends JsonDeserializer&lt;String&gt; {
  
      @Override
      public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
          final JsonNode node = p.getCodec().readTree(p);
          return node.toString();
      }
  
      public Class&lt;Object&gt; handledType() {
          return Object.class;
      }
  }
  </code></pre>
  <p>Is it possible to bind the root JSON object being deserialized to a particular property of the final instance?</p>