/** * Create a resource instance from the object for the given content type. Properties from * the object are copied into the resulting Resource. Also, links are injected for appropriate * relationships defined via HyperExpress.relationships(), using any HyperExpress.bind() or * HyperExpress.tokenBinder() settings to populate the tokens in the URLs. * * @param object * @param contentType * @return */ public static Resource createResource(Object object, String contentType) { return INSTANCE._createResource(object, contentType); }
private Collection<Resource> _createResources(Collection<?> components, Class<?> componentType, String contentType) { if (components == null || components.isEmpty()) return Collections.emptyList(); List<Resource> resources = new ArrayList<Resource>(components.size()); Resource childResource = null; for (Object component : components) { if (Resource.class.isAssignableFrom(component.getClass())) { childResource = (Resource) component; _assignResourceLinks(childResource, component, componentType); } else { childResource = _createResource(component, contentType); } } return resources; }
childResource = _createResource(component, contentType);