Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaTypeConfigurationCustomizer(s) are not applied on HalConfiguration #2436

Open
vierbergenlars opened this issue Nov 18, 2024 · 0 comments
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@vierbergenlars
Copy link
Contributor

vierbergenlars commented Nov 18, 2024

spring-hateoas has introduced MediaTypeConfigurationCustomizer, which can be used to configure/modify HalConfiguration and HalFormsConfiguration in an additive way instead of overwriting the whole bean. (see spring-projects/spring-hateoas#2035)

However, these customizers are not applied in spring-data-rest where HalConfiguration or HalFormsConfiguration are used (in RepositoryRestMvcConfiguration), leading to an inconsistency between the configuration as used by spring-hateoas and the one used by spring-data-rest.

I bumped into this because I am using a customizer-based configuration, and its behavior is different when using only spring-hateoas or when having a dependency on spring-data-rest-webmvc (even though it is not being used for this particular endpoint).

	@Bean
	MediaTypeConfigurationCustomizer<HalConfiguration> halConfigurationCustomizer() {
		return halConfiguration -> halConfiguration
				.withRenderSingleLinksFor("supplier", RenderSingleLinks.AS_ARRAY);
	}

Without spring-data-rest-webmvc, the response looks like expected (the supplier link is an array, even though only one link item is present)

{
    "id":null,
    "received":null,
    "supplier":null,
    "_version":0,
    "pay_before":null,
    "total_amount":null,
    "_links":{
        "supplier":[
            {"href":"test"}
        ]
    }
}

When adding a dependency on spring-data-rest-webmvc, the 'render single links' customization seems to get ignored, falling back to the default:

{
  "received" : null,
  "pay_before" : null,
  "total_amount" : null,
  "_links" : {
    "supplier" : {
      "href" : "test"
    }
  }
}

I have an example application displaying the issue here:
invoice-api.zip.
This shows the issue with spring-data-rest-webmvc.
To see the behavior without spring-data-rest-webmvc, either uncomment the exclude line in build.gradle or remove the whole dependeny on the spring-data-rest starter)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants