org.springframework.hateoas.server.LinkRelationProvider Java Examples

The following examples show how to use org.springframework.hateoas.server.LinkRelationProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FeignHalAutoConfigurationTests.java    From spring-cloud-openfeign with Apache License 2.0 6 votes vote down vote up
@Test
public void halJacksonHttpMessageConverter() {
	ObjectMapper mapper = new ObjectMapper();
	when(objectMapper.getIfAvailable(any())).thenReturn(mapper);

	when(halConfiguration.getIfAvailable(any()))
			.thenReturn(mock(HalConfiguration.class));
	when(relProvider.getIfAvailable()).thenReturn(mock(LinkRelationProvider.class));
	when(curieProvider.getIfAvailable(any())).thenReturn(mock(CurieProvider.class));
	when(messageResolver.getIfAvailable()).thenReturn(mock(MessageResolver.class));

	TypeConstrainedMappingJackson2HttpMessageConverter converter = feignHalAutoConfiguration
			.halJacksonHttpMessageConverter(objectMapper, halConfiguration,
					messageResolver, curieProvider, relProvider);

	assertThat(converter).isNotNull();
	assertThat(converter.getObjectMapper()).isNotNull();
	assertThat(converter.getSupportedMediaTypes()).isEqualTo(Arrays.asList(HAL_JSON));

	assertThat(Jackson2HalModule.isAlreadyRegisteredIn(converter.getObjectMapper()))
			.isTrue();
}
 
Example #2
Source File: FeignHalAutoConfiguration.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public TypeConstrainedMappingJackson2HttpMessageConverter halJacksonHttpMessageConverter(
		ObjectProvider<ObjectMapper> objectMapper,
		ObjectProvider<HalConfiguration> halConfiguration,
		ObjectProvider<MessageResolver> messageResolver,
		ObjectProvider<CurieProvider> curieProvider,
		ObjectProvider<LinkRelationProvider> linkRelationProvider) {

	ObjectMapper mapper = objectMapper.getIfAvailable(ObjectMapper::new).copy();
	mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

	HalConfiguration configuration = halConfiguration
			.getIfAvailable(HalConfiguration::new);

	CurieProvider curieProviderInstance = curieProvider
			.getIfAvailable(() -> new DefaultCurieProvider(Collections.emptyMap()));

	Jackson2HalModule.HalHandlerInstantiator halHandlerInstantiator = new Jackson2HalModule.HalHandlerInstantiator(
			linkRelationProvider.getIfAvailable(), curieProviderInstance,
			messageResolver.getIfAvailable(), configuration);

	mapper.setHandlerInstantiator(halHandlerInstantiator);

	if (!Jackson2HalModule.isAlreadyRegisteredIn(mapper)) {
		Jackson2HalModule halModule = new Jackson2HalModule();
		mapper.registerModule(halModule);
	}

	TypeConstrainedMappingJackson2HttpMessageConverter converter = new TypeConstrainedMappingJackson2HttpMessageConverter(
			RepresentationModel.class);
	converter.setSupportedMediaTypes(Arrays.asList(HAL_JSON));
	converter.setObjectMapper(mapper);
	return converter;
}
 
Example #3
Source File: SimpleIdentifiableRepresentationModelAssembler.java    From spring-hateoas-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Default a assembler based on Spring MVC controller, resource type, and {@link LinkRelationProvider}. With this
 * combination of information, resources can be defined.
 *
 * @see #setBasePath(String) to adjust base path to something like "/api"/
 * @param controllerClass - Spring MVC controller to base links off of
 * @param relProvider
 */
public SimpleIdentifiableRepresentationModelAssembler(Class<?> controllerClass, LinkRelationProvider relProvider) {

	this.controllerClass = controllerClass;
	this.relProvider = relProvider;

	// Find the "T" type contained in "T extends Identifiable<?>", e.g.
	// SimpleIdentifiableRepresentationModelAssembler<User> -> User
	this.resourceType = GenericTypeResolver.resolveTypeArgument(this.getClass(),
			SimpleIdentifiableRepresentationModelAssembler.class);
}
 
Example #4
Source File: BarResourceAssembler.java    From friendly-id with Apache License 2.0 4 votes vote down vote up
public BarResourceAssembler(LinkRelationProvider relProvider) {
	super(BarController.class, BarResource.class);
	this.relProvider = relProvider;
}
 
Example #5
Source File: JsonConfiguration.java    From friendly-id with Apache License 2.0 4 votes vote down vote up
@Bean
public BarResourceAssembler barResourceAssembler(LinkRelationProvider relProvider) {
	return new BarResourceAssembler(relProvider);
}
 
Example #6
Source File: SpringDocHateoasConfiguration.java    From springdoc-openapi with Apache License 2.0 3 votes vote down vote up
/**
 * Collection model content converter collection model content converter.
 *
 * @param halProvider the hal provider
 * @param linkRelationProvider the link relation provider
 * @return the collection model content converter
 */
@Bean
@ConditionalOnMissingBean
@Lazy(false)
CollectionModelContentConverter collectionModelContentConverter(HateoasHalProvider halProvider, LinkRelationProvider linkRelationProvider) {
	return halProvider.isHalEnabled() ? new CollectionModelContentConverter(linkRelationProvider) : null;
}
 
Example #7
Source File: CollectionModelContentConverter.java    From springdoc-openapi with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new Collection model content converter.
 *
 * @param linkRelationProvider the link relation provider
 */
public CollectionModelContentConverter(LinkRelationProvider linkRelationProvider) {
	this.linkRelationProvider = linkRelationProvider;
}