title: How to deserialize json to java object, when you expose interface RequestBody in rest call?
body: <p>i have following project structure as maven project : </p>
  
  <pre><code>Project 1 -&gt; Core-part(having interface) :
  
  interface Foo{
  
    public String getStr1();
    public setStr1(String str1);
  
    public List&lt;? extends Bar&gt; getBarList();
    public setBarList(List&lt;? extends Bar&gt; barList);
  }
  
  interface Bar{
     public String getStr2();
     public setStr2(String str2);
  }
  </code></pre>
  
  <p>Project 2 -> Impl-part(having implementation)</p>
  
  <pre><code>Public class FooImpl implements Foo{
    private String str1;
    private List&lt;? extends Bar&gt; barList;
  
    public String getStr1(){
        return str1;
    }
    public setStr1(String str1){
      this.str1= str1;
    }
    public List&lt;? extends Bar&gt; getBarList(){
      return barList;
    }
    public setBarList(List&lt;? extends Bar&gt; barList){
      this.barList= barList;
    }
  
  }
  
  Public class BarImpl implements Bar{
    private String str2;
  
    public String getStr2(){
        return str2;
    }
    public setStr2(String str2){
      this.str2= str2;
    }
  }
  </code></pre>
  
  <p>Project 3 -> Rest-part (having rest calls)</p>
  
  <pre><code>@RestController
  public class BaseDataController {
  
    @RequestMapping(method=RequestMethod.POST,value="/save")
    public Foo saveFoo(@RequestBody Foo foo) {
          return foo;
  
    }
  }
  </code></pre>
  
  <p>core-part JAR is included in impl-part and impl-part JAR is included in Rest-part, and i deploy Rest-part WAR file.</p>
  
  <p>I am returning the same object in the rest call, but it gives error when this function is called. 
  i tried registering deserializer for the Foo interface via this code :</p>
  
  <pre><code>@Configuration
  public class WebConfig extends WebMvcConfigurationSupport {
    @Bean
    @Primary
    public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter() {
      MappingJackson2HttpMessageConverter jsonConverter = new  MappingJackson2HttpMessageConverter();
      ObjectMapper objectMapper = new ObjectMapper();
  
      SimpleModule simpleModule = new SimpleModule();
      simpleModule.addDeserializer(Demo.class, new FooDeserializer());
      simpleModule.addDeserializer(Demo.class, new BarDeserializer());
      objectMapper.registerModule(simpleModule);
      objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
      jsonConverter.setObjectMapper(objectMapper);
      return jsonConverter;
    }
  </code></pre>
  
  <p>FooDeserializer is as follows :</p>
  
  <pre><code>public class FooDeserializer extends JsonDeserializer&lt;Foo&gt; {
  
    @Override
    public Foo deserialize(JsonParser jp, DeserializationContext    context) throws IOException {
         ObjectMapper mapper = (ObjectMapper) jp.getCodec();
         ObjectNode root = mapper.readTree(jp);
         return mapper.readValue(root.toString(),  FooImpl.class);
    }
  }
  
  public class BarDeserializer extends JsonDeserializer&lt;Bar&gt; {
  
    @Override
    public Bar deserialize(JsonParser jp, DeserializationContext    context) throws IOException {
         ObjectMapper mapper = (ObjectMapper) jp.getCodec();
         ObjectNode root = mapper.readTree(jp);
         return mapper.readValue(root.toString(),  BarImpl.class);
    }
  }
  </code></pre>
  
  <p>This code doesn't solve my problem and throws error for conversion of json to object. What should i do to solve this issue. </p>
  
  <p>And if i have scenario of interface as member of another interface, how this will be solved. As i tries registering this deserializer too in rest layer project.</p>
  
  <p>The request i post for this:</p>
  
  <pre><code>POST /save HTTP/1.1
  Host: XXX
  Content-Type: application/json
  Cache-Control: no-cache
  Postman-Token: XXX
  
  {  
     "str1":"aaa",
     "barList":[  
    {  
       "str2":"bbb"
    }
    ]
  }
  </code></pre>
  
  <p>i have just structured this details minimally, in actual data will increase.</p>
  
  <p>The error which i get is :</p>
  
  <pre><code>abstract types either need to be mapped to concrete types, have custom  deserializer, or contain additional type information\n at [Source:   java.io.PushbackInputStream@32e11e31; line: 6, column: 7]
  </code></pre>