Reusing internal implementation to transform JSON mapping to ES mapping

If anyone has a similar question in the future; withJson is a general deserializer than will convert a JSON to internal ES objects without having to make a request to the cluster itself.

  public static Map<String, Property> jsonToMapping(String json) {
    TypeMapping typeMapping = withJson(new TypeMapping.Builder(), new StringReader(json), new JacksonJsonpMapper()).build();
    return typeMapping.properties();
  }

  private static <T, B extends ObjectBuilder<T>> B withJson(
      B builder, Reader json, JsonpMapper mapper) {
    // Find which deserializer is needed
    JsonpDeserializer<?> classDeserializer =
        JsonpMapperBase.findDeserializer(builder.getClass().getEnclosingClass());

    @SuppressWarnings("unchecked")
    ObjectDeserializer<B> builderDeserializer =
        (ObjectDeserializer<B>) DelegatingDeserializer.unwrap(classDeserializer);

    JsonParser parser = mapper.jsonProvider().createParser(json);
    builderDeserializer.deserialize(builder, parser, mapper, parser.next());
    return builder;
  }