title: How use Custom Conversions Spring-data-elasticsearch
body: <p>I am using Elasticist 4.0.1. I have a field</p>
  <pre><code>@Field(type = FieldType.Nested, index = false, includeInParent = true)
  private Map&lt;String, Map&lt;String, List&lt;City&gt;&gt;&gt; province = new HashMap&lt;&gt;();
  </code></pre>
  <p>According to the documentation, I did Custom Conversions.</p>
  <pre><code>public class ElasticConfig extends AbstractElasticsearchConfiguration {
  
  
  @Bean
  @Override
  public RestHighLevelClient elasticsearchClient() {
  
      ClientConfiguration clientConfiguration
              = ClientConfiguration.builder()
              .connectedTo(&quot;0.0.0.0:9200&quot;)
              .build();
  
      return RestClients.create(clientConfiguration).rest();
  }
  @Bean
  public ElasticsearchOperations elasticsearchTemplate() {
      return new ElasticsearchRestTemplate(elasticsearchClient());
  }
  
  @Bean
  @Override
  public ElasticsearchCustomConversions elasticsearchCustomConversions() {
      return new ElasticsearchCustomConversions(Arrays.asList(new ProvinceToMap(), new MapToProvince()));
  }
  
  @WritingConverter
  static class ProvinceToMap implements Converter&lt;Map&lt;String, Map&lt;String, ArrayList&lt;City&gt;&gt;&gt;, Map&lt;String, Object&gt;&gt; {
  
      @Override
      public Map&lt;String, Object&gt; convert(Map&lt;String, Map&lt;String, ArrayList&lt;City&gt;&gt;&gt; userTaskEvents) {
  
          HashMap&lt;String, Object&gt; target = new HashMap&lt;&gt;();
  
          for(Map.Entry&lt;String, Map&lt;String, ArrayList&lt;City&gt;&gt;&gt; entry: userTaskEvents.entrySet()) {
              target.put(entry.getKey(), entry.getValue());
  
          }
  
          return target;
      }
  
  }
  
  @ReadingConverter
  static class MapToProvince implements Converter&lt;Map&lt;String, Object&gt;, Map&lt;String, Map&lt;String, ArrayList&lt;City&gt;&gt;&gt;&gt; {
  
      @Override
      public Map&lt;String, Map&lt;String, ArrayList&lt;City&gt;&gt;&gt; convert(Map&lt;String, Object&gt; stringObjectMap) {
          ObjectMapper oMapper = new ObjectMapper();
  
          Map&lt;String, Map&lt;String, ArrayList&lt;City&gt;&gt;&gt; target = new HashMap&lt;&gt;();
  
          for(Map.Entry&lt;String, Object&gt; entry: stringObjectMap.entrySet()) {
              Map&lt;String, ArrayList&lt;Map&lt;String, Object&gt;&gt;&gt; event = oMapper.convertValue(entry.getValue(), Map.class);
  
              target.put(entry.getKey(), conv);
          }
  
          return target;
      }
  </code></pre>
  <p>When I execute this piece of code.</p>
  <pre><code> for(Map.Entry&lt;String, Map&lt;String, ArrayList&lt;City&gt;&gt;&gt; entry: userTaskEvents.entrySet()) {
              target.put(entry.getKey(), entry.getValue());
  
              for (Map.Entry&lt;String, ArrayList&lt;City&gt;&gt; aaa: entry.getValue().entrySet()) {
                  for (TestClass tt: aaa.getValue())
                      System.out.println(tt.getNameCity());
              }
  
          }
  </code></pre>
  <p>I get an error</p>
  <pre><code>java.lang.ClassCastException: java.util.HashMap cannot be cast to org.elasticsearch.example.model.City
  at kz.elasticsearch.example.config.ElasticConfig$UserTaskEventToMap.convert(ElasticConfig.java:66) ~[classes/:na]
  at kz.elasticsearch.example.config.ElasticConfig$UserTaskEventToMap.convert(ElasticConfig.java:54) ~[classes/:na]
  </code></pre>
  <p>...</p>
  <p>Maybe I'm not doing it right. I noticed that when I receive data from elastic, the data is cast be as Map.</p>
  <p>How to use the parts correctly 4.0.1. I've used Jackson before.</p>