title: Spring deserialization with autowired properties - manual reuse possible?
body: <p>I have an Object <code>doc</code> which has its own Deserializer annotated, i.e.</p>
  
  <pre><code>@JsonSerialize(using = DocDeSerializer.class)
  public class Doc {
  </code></pre>
  
  <p>and the Deserializer looks like</p>
  
  <pre><code>@Service
  public class DocDeserializer&lt;T&gt; extends JsonDeserializer&lt;Doc&gt; i{
  
  @Autowired
  private PropertyController ctrlProp;
  
  @Override
  public Doc deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
  ...
  </code></pre>
  
  <p>The complete deserialization for HTTP-requests works fine. But now I have the challenge to convert a String into a <code>doc</code>. My approach with </p>
  
  <pre><code>final ObjectMapper objectMapper = new ObjectMapper();
  final Doc myDoc = objectMapper.readValue(strContent, Doc.class);
  </code></pre>
  
  <p>fails. The reason is that the autowired classes are not initiated properly, i.e. <code>ctrlProp</code> is not initiated (=<code>null</code>). So, my question is:</p>
  
  <p>Is there a <em>simple</em> way to reuse the Deserializer from Spring? And if so, how?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>After investigations I found out that it has to do with the config of a HttpConverts. So my config looks like:</p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  public class WebConfig implements WebMvcConfigurer {
  
      @Bean
      @Primary
      public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
          final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
          final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
          converter.setObjectMapper(builder.build());
          return converter;
      }
  
      @Override
      public void configureMessageConverters(List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) {
          final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
  
  ....
          converters.add(mappingJackson2HttpMessageConverter());
      }
  }
  </code></pre>
  
  <p>which is used in </p>
  
  <pre><code>@RestController
  public class MyClass
  
  @Autowired
  private MappingJackson2HttpMessageConverter myJackson;
  </code></pre>
  
  <p>but somehow this fails as well :-( Just for the sake of clarity what was tried...</p>