private Descriptor buildRepresentationDescriptor(Class<?> type) {

    ResourceMetadata metadata = mappings.getMetadataFor(type);

    return descriptor()
        . //
        id(getRepresentationDescriptorId(metadata))
        . //
        href(entityLinks.linkFor(type).slash("schema").toString())
        . //
        doc(getDocFor(metadata.getItemResourceDescription()))
        . //
        descriptors(buildPropertyDescriptors(type, metadata.getItemResourceRel()))
        . //
        build();
  }
  private Descriptor buildItemResourceDescriptor(
      RootResourceInformation resourceInformation,
      Descriptor representationDescriptor,
      HttpMethod method) {

    PersistentEntity<?, ?> entity = resourceInformation.getPersistentEntity();
    ResourceMetadata metadata = mappings.getMetadataFor(entity.getType());

    return descriptor()
        . //
        id(prefix(method).concat(metadata.getItemResourceRel()))
        . //
        name(metadata.getItemResourceRel())
        . //
        type(getType(method))
        . //
        doc(getDocFor(metadata.getItemResourceDescription()))
        . //
        rt("#".concat(representationDescriptor.getId()))
        . //
        descriptors(getProjectionDescriptor(entity.getType(), method))
        . //
        build();
  }
  /*
   * (non-Javadoc)
   * @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
   */
  @Override
  public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

    PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity((Class<?>) source);
    final ResourceMetadata metadata = mappings.getMappingFor(persistentEntity.getType());
    final JsonSchema jsonSchema =
        new JsonSchema(
            persistentEntity.getName(), accessor.getMessage(metadata.getItemResourceDescription()));

    persistentEntity.doWithProperties(
        new SimplePropertyHandler() {

          /*
           * (non-Javadoc)
           * @see org.springframework.data.mapping.PropertyHandler#doWithPersistentProperty(org.springframework.data.mapping.PersistentProperty)
           */
          @Override
          public void doWithPersistentProperty(PersistentProperty<?> persistentProperty) {

            Class<?> propertyType = persistentProperty.getType();
            String type = uncapitalize(propertyType.getSimpleName());

            ResourceMapping propertyMapping = metadata.getMappingFor(persistentProperty);
            ResourceDescription description = propertyMapping.getDescription();
            String message = accessor.getMessage(description);

            Property property =
                persistentProperty.isCollectionLike()
                    ? //
                    new ArrayProperty("array", message, false)
                    : new Property(type, message, false);

            jsonSchema.addProperty(persistentProperty.getName(), property);
          }
        });

    final List<Link> links = new ArrayList<Link>();

    persistentEntity.doWithAssociations(
        new SimpleAssociationHandler() {

          /*
           * (non-Javadoc)
           * @see org.springframework.data.mapping.AssociationHandler#doWithAssociation(org.springframework.data.mapping.Association)
           */
          @Override
          public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {

            PersistentProperty<?> persistentProperty = association.getInverse();

            if (!metadata.isExported(persistentProperty)) {
              return;
            }

            RepositoryLinkBuilder builder =
                new RepositoryLinkBuilder(metadata, config.getBaseUri()).slash("{id}");
            maybeAddAssociationLink(builder, mappings, persistentProperty, links);
          }
        });

    jsonSchema.add(links);

    return jsonSchema;
  }