title: Deserializing selected property names only (Jackson)
body: <p>Let's say we have following JSON,</p>
  
  <pre><code>{
      "id": "imgsId1",
      "type": "Fruits",
      "name": "Tropical",
      "image":
       {
           "url": "images/img1.jpg",
           "width": 300,
           "height": 300
      },
      "thumbnail":
      {
          "url": "images/thumbnails/img11.jpg",
          "width": 50,
          "height": 50
      }
  }
  </code></pre>
  
  <p>And in Java Class, we have all fields matching with above JSON. </p>
  
  <p>Each time list of fields to be Deserialized depends on customer who sends the information. </p>
  
  <p>For example for customer 1, we want to only read back following values, <strong>(and skip other properties even if provided in JSON)</strong></p>
  
  <pre><code>String[] propertiesToFilter1 = {"type","image.url"};
  </code></pre>
  
  <p>For example for customer 2, we want to read back following values, <strong>(and skip other properties even if provided in JSON)</strong></p>
  
  <pre><code>String[] propertiesToFilter2 = {"type","image.url", "image.width"};
  </code></pre>
  
  <p>When Deserializing JSON using Jackson, is it possible to provide above array which includes which fields need to be Deserialized,</p>
  
  <pre><code>ImageInfo obj1 = (ImageInfo)objectMapper.readValue(jsonStr, ImageInfo.class);
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>On researching on net, i saw that one of the options could be via using </p>
  
  <pre><code>FilterProvider filterProvider = new SimpleFilterProvider().addFilter("filterName1", 
                      SimpleBeanPropertyFilter.serializeAllExcept(propertiesToFilter1));
  
  objectMapper.setFilters(filterProvider);
  </code></pre>
  
  <p>But i think this is good, if we want to keep reusing the same "filterName1" for multiple customers.</p>
  
  <p>In this scenario, it's little bit different because, we customize list of fields each customer can update. So each customer has different list of JSON fields they can update in different classes. </p>
  
  <p>If we start defining different filter names for each customer, it will be a long list, and lookup will have performance impact.</p>
  
  <p>So was looking for solution, where i can check list of fields allowed to be processed at runtime, when constructing back object using objectMapper.readValue() method.</p>
  
  <p><strong>Update 2 (Apr 25 2016):</strong></p>
  
  <p>Going through other Jackson questions, saw a similar question here, </p>
  
  <p><a href="https://stackoverflow.com/questions/12305438/jackson-dynamic-filtering-of-properties-during-deserialization">Jackson Dynamic filtering of properties during deserialization</a></p>
  
  <p>Using the approach listed below by creating custom "static ObjectMapper", the issue with this approach is we running Reflection API multiple times. </p>
  
  <ul>
  <li><p>First time Jackson parser is populating all fields using
  Reflection API when Deserializing JSON to Java Object</p></li>
  <li><p>Second time, since we can't take all fields that were populated by
  Jackson parser, for populate data into another object, we again need to run through Reflection API to populate another object.</p></li>
  </ul>
  
  <p>This could result in lot of overhead.</p>
  
  <p>Using the approach defined in above link provided, i think using "BeanDeserializerModifier" seems to be best approach. Now the question is, since we are also using Factory based approach to initialize ObjectMapper, we don't want to hard code all arrays for different customers.</p>
  
  <p><strong>Wanted to check if it's possible to provide the String[] array with list of Properties to be considered at runtime to "BeanDeserializerModifier"?</strong> </p>
  
  <p>something similar to,</p>
  
  <pre><code>String[] propertiesToFilter2 = {"type","image.url", "image.width"};
  
  BeanDeserializerModifier curBeanDeserializerModifier = 
              getBeanDeserializerModifierInstance();
  
  curBeanDeserializerModifier.setPropertiesToConsider(propertiesToFilter2);
  </code></pre>
  
  <p>Thanks</p>