protected RepositoryRestRequest getRequest(Class<?> domainType, RequestParameters parameters) {

    Assert.notNull(domainType, "Domain type must not be null!");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameters(parameters.asMap());

    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes);

    PersistentEntity<?, ?> entity = repositories.getPersistentEntity(domainType);

    return new RepositoryRestRequest(
        entity,
        new ServletWebRequest(request),
        mappings.getMappingFor(domainType),
        invokerFactory.getInvokerFor(domainType));
  }
  /*
   * (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;
  }
 protected ResourceMetadata getMetadata(Class<?> domainType) {
   return mappings.getMappingFor(domainType);
 }