org.springframework.hateoas.Resource.getContent()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(77)

本文整理了Java中org.springframework.hateoas.Resource.getContent方法的一些代码示例,展示了Resource.getContent的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.getContent方法的具体详情如下:
包路径:org.springframework.hateoas.Resource
类名称:Resource
方法名:getContent

Resource.getContent介绍

[英]Returns the underlying entity.
[中]返回基础实体。

代码示例

代码示例来源:origin: spring-projects/spring-hateoas

@Override
public String toString() {
  return String.format("Resource { content: %s, %s }", getContent(), super.toString());
}

代码示例来源:origin: spring-projects/spring-hateoas

public static Map<String, Object> findProperties(Object object) {
  if (object.getClass().equals(Resource.class)) {
    return findProperties(((Resource<?>) object).getContent());
  }
  return getPropertyDescriptors(object.getClass())
    .collect(HashMap::new,
      (hashMap, descriptor) -> {
        try {
          Method readMethod = descriptor.getReadMethod();
          ReflectionUtils.makeAccessible(readMethod);
          hashMap.put(descriptor.getName(), readMethod.invoke(object));
        } catch (IllegalAccessException | InvocationTargetException e) {
          throw new RuntimeException(e);
        }
      },
      HashMap::putAll);
}

代码示例来源:origin: spring-projects/spring-hateoas

/**
 * Convert a {@link Resource} into a list of {@link UberData}s, containing links and content.
 *
 * @param resource
 * @return
 */
static List<UberData> extractLinksAndContent(Resource<?> resource) {
  List<UberData> data = extractLinks(resource);
  extractContent(resource.getContent()).ifPresent(data::add);
  return data;
}

代码示例来源:origin: spring-projects/spring-hateoas

@Override
@SuppressWarnings("unchecked")
public Class<?> getRelTargetType() {
  Object peek = peek();
  if (peek == null) {
    return null;
  }
  peek = peek instanceof Resource ? ((Resource<Object>) peek).getContent() : peek;
  return AopUtils.getTargetClass(peek);
}

代码示例来源:origin: spring-projects/spring-data-rest

/**
 * Returns whether the given {@link Resource} matches the given target {@link ResolvableType}. We inspect the
 * {@link Resource}'s value to determine the match.
 *
 * @param resource
 * @param target must not be {@literal null}.
 * @return whether the given {@link Resource} can be assigned to the given target {@link ResolvableType}
 */
private static boolean isValueTypeMatch(Resource<?> resource, ResolvableType target) {
  if (resource == null || !isRawTypeAssignable(target, resource.getClass())) {
    return false;
  }
  Object content = resource.getContent();
  if (content == null) {
    return false;
  }
  ResolvableType type = findGenericType(target, Resource.class);
  return type != null && type.getGeneric(0).isAssignableFrom(ResolvableType.forClass(content.getClass()));
}

代码示例来源:origin: spring-projects/spring-hateoas

/**
 * Returns whether the given {@link Resource} matches the given target {@link ResolvableType}. We inspect the
 * {@link Resource}'s value to determine the match.
 * 
 * @param resource
 * @param target must not be {@literal null}.
 * @return whether the given {@link Resource} can be assigned to the given target {@link ResolvableType}
 */
private static boolean isValueTypeMatch(Resource<?> resource, ResolvableType target) {
  if (resource == null || !isRawTypeAssignable(target, resource.getClass())) {
    return false;
  }
  Object content = resource.getContent();
  if (content == null) {
    return false;
  }
  ResolvableType type = findGenericType(target, Resource.class);
  return type != null && type.getGeneric(0).isAssignableFrom(ResolvableType.forClass(content.getClass()));
}

代码示例来源:origin: spring-projects/spring-hateoas

private static List<CollectionJsonItem<?>> resourcesToCollectionJsonItems(Resources<?> resources) {
  
  return resources.getContent().stream()
    .map(content -> {
      if (ClassUtils.isAssignableValue(Resource.class, content)) {
        Resource resource = (Resource) content;
        return new CollectionJsonItem<>()
          .withHref(resource.getRequiredLink(IanaLinkRelation.SELF.value()).getHref())
          .withLinks(withoutSelfLink(resource.getLinks()))
          .withRawData(resource.getContent());
      } else {
        return new CollectionJsonItem<>().withRawData(content);
      }
    })
    .collect(Collectors.toList());
}

代码示例来源:origin: spring-projects/spring-data-rest

Object content = ((Resource<?>) resource).getContent();
if (content instanceof Iterable) {

代码示例来源:origin: spring-projects/spring-hateoas

@Override
public void serialize(Resource<?> value, JsonGenerator gen, SerializerProvider provider) throws IOException {
  HalFormsDocument<?> doc = HalFormsDocument.forResource(value.getContent()) //
      .withLinks(value.getLinks()) //
      .withTemplates(findTemplates(value));
  provider
    .findValueSerializer(HalFormsDocument.class, property)
    .serialize(doc, gen, provider);
}

代码示例来源:origin: odrotbohm/spring-restbucks

@Override
  public Resource<Order> process(Resource<Order> resource) {

    Order order = resource.getContent();

    if (!order.isPaid()) {
      resource.add(paymentLinks.getPaymentLink(order));
    }

    if (order.isReady()) {
      resource.add(paymentLinks.getReceiptLink(order));
    }

    return resource;
  }
}

代码示例来源:origin: odrotbohm/spring-restbucks

@Override
  public Resource<Order> process(Resource<Order> resource) {

    Order order = resource.getContent();

    if (!order.isPaid()) {
      resource.add(entityLinks.linkForSingleResource(order).withRel(CANCEL_REL));
      resource.add(entityLinks.linkForSingleResource(order).withRel(UPDATE_REL));
    }

    return resource;
  }
}

代码示例来源:origin: spring-projects/spring-data-rest

/**
   * Creates a {@link ProjectionResource} for the given {@link TargetAware}.
   *
   * @param value must not be {@literal null}.
   * @return
   */
  private ProjectionResource toResource(TargetAware value) {
    Object target = value.getTarget();
    ResourceMetadata metadata = associations.getMetadataFor(value.getTargetClass());
    Links links = metadata.isExported() ? collector.getLinksFor(target) : new Links();
    Resource<TargetAware> resource = invoker.invokeProcessorsFor(new Resource<TargetAware>(value, links));
    return new ProjectionResource(resource.getContent(), resource.getLinks());
  }
}

代码示例来源:origin: BlackPepperSoftware/bowman

LinkedResourceMethodHandler(Resource resource, RestOperations restOperations, ClientProxyFactory proxyFactory) {
  super(resource.getContent().getClass());
  this.restOperations = restOperations;
  this.proxyFactory = proxyFactory;
  this.resource = resource;
}

代码示例来源:origin: spring-projects/spring-hateoas

@Override
public void serialize(Resource<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
  String href = value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref();
  CollectionJson<?> collectionJson = new CollectionJson()
    .withVersion("1.0")
    .withHref(href)
    .withLinks(withoutSelfLink(value.getLinks()))
    .withItems(Collections.singletonList(new CollectionJsonItem<>()
      .withHref(href)
      .withLinks(withoutSelfLink(value.getLinks()))
      .withRawData(value.getContent())))
    .withQueries(findQueries(value))
    .withTemplate(findTemplate(value));
  CollectionJsonDocument<?> doc = new CollectionJsonDocument<>(collectionJson);
  provider
    .findValueSerializer(CollectionJsonDocument.class, property)
    .serialize(doc, jgen, provider);
}

代码示例来源:origin: erafaelmanuel/cshop

@PostMapping("/cart/add")
public String doAddItem(@RequestParam("itemId") String itemId,
            @SessionAttribute(name = "cartItems") List<Item> cartItems, Model model) {
  cartItems.add(itemService.findById(itemId).getContent());
  model.addAttribute("cartItems", cartItems);
  return "fragment/nav/cart";
}

代码示例来源:origin: org.springframework.hateoas/spring-hateoas

@Override
@SuppressWarnings("unchecked")
public Class<?> getRelTargetType() {
  Object peek = peek();
  if (peek == null) {
    return null;
  }
  peek = peek instanceof Resource ? ((Resource<Object>) peek).getContent() : peek;
  return AopUtils.getTargetClass(peek);
}

代码示例来源:origin: sakaiproject/sakai

@Override
  public Resource<InlineRubric> process(Resource<InlineRubric> rubricResource) {
    InlineRubric rubric = rubricResource.getContent();
    if (rubric.getToolItemAssociations() != null && rubric.getToolItemAssociations().size() > 0) {
      rubric.getMetadata().setLocked(true);
    }
    return rubricResource;
  }
}

代码示例来源:origin: sakaiproject/sakai

@Override
  public Resource<Rubric> process(Resource<Rubric> rubricResource) {
    Rubric rubric = rubricResource.getContent();
    if (rubric.getToolItemAssociations() != null && rubric.getToolItemAssociations().size() > 0) {
      rubric.getMetadata().setLocked(true);
    }
    return rubricResource;
  }
}

代码示例来源:origin: BlackPepperSoftware/bowman

@Override
public <T> T create(Resource<T> resource, RestOperations restOperations) {
  @SuppressWarnings("unchecked")
  Class<T> entityType = (Class<T>) resource.getContent().getClass();
  
  MethodHandlerChain handlerChain = new MethodHandlerChain(asList(
    new ResourceIdMethodHandler(resource),
    new LinkedResourceMethodHandler(resource, restOperations, this),
    new SimplePropertyMethodHandler<>(resource)
  ));
  
  return createProxyInstance(entityType, handlerChain);
}

代码示例来源:origin: dschulten/hydra-java

@Test
  public void testRecursivelyCreateObjectNestedBean() throws Exception {
    LinkedMultiValueMap<String, String> formValues = new LinkedMultiValueMap<String, String>();
    formValues.add("workPerformed.name", "foo");
    formValues.add("location", "Harmonie Heilbronn");
    Event event = (Event) converter.recursivelyCreateObject(Event.class, formValues, "");
    assertEquals("foo", event.getWorkPerformed()
        .getContent().name);
    assertEquals("Harmonie Heilbronn", event.location);
  }
}

相关文章

微信公众号

最新文章

更多