when spring.main.jackson.property-naming-strategy = KEBAB_CASE with an embedded config server in the same jvm as the spring app and client. seeing Environment contains empty list propertySources
omitting property-naming-strategy and environment deserializes correctly.
not a problem with config server or client, but within RestTemplate - proved with wireshark server is sending property-sources
got to configure the client to use the same property-naming-strategy fore deserialization somehow.
jackson core 2.11.1 spring boot 2.4.0-M1
@Test
public void testRemoteEnvironment() {
ResponseEntity<Environment> response = null;
HttpHeaders headers = new HttpHeaders();
headers.setAccept(
Collections.singletonList(MediaType.parseMediaType(V2_JSON)));
restTemplate = new RestTemplate();
try {
final HttpEntity<Void> entity = new HttpEntity<>((Void) null, headers);
response = restTemplate.exchange("http://localhost:9091/fmcs/dev/master", HttpMethod.GET, entity,
Environment.class, new Object[0]);
} catch (HttpClientErrorException e) {
if (e.getStatusCode() != HttpStatus.NOT_FOUND) {
throw e;
}
} catch (ResourceAccessException e) {
}
if (response == null || response.getStatusCode() != HttpStatus.OK) {
Assert.fail();
}
Environment result = response.getBody();
Assert.assertNotNull(result.getName());
Assert.assertNotNull(result.getProfiles());
Assert.assertFalse(result.getPropertySources().isEmpty());
}
Comment From: wilkinsona
You can configure a RestTemplate
's HTTP message converters to take control over what it can deserialise and how. It sounds like you need to configure it with a custom MappingJackson2HttpMessageConverter
that's using an appropriately configured ObjectMapper
. Alternatively, you could use the auto-configured RestTemplateBuilder
to create a RestTemplate
rather than calling new RestTemplate()
. Using the builder will result in a RestTemplate
that uses a Jackson HTTP message converter with the auto-configured ObjectMapper
and its custom property naming strategy.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
Comment From: warrenc5
Thanks @wilkinsona You will need to do this in your spring cloud config client code too right?
ConfigServicePropertySourceLocator getSecureRestTemplate. the BaseSettings propertyNamingStrategy null Because you do a new RestTemplate in getSecureRestTemplate and not using an autowired/builder approach.
Comment From: warrenc5
https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java line 308
Let me know - I can submit a patch :)
Comment From: wilkinsona
Thanks gaylord!
Please don't use the term gaylord. I assume this wasn't your intent, but for many it's homophobic abuse which is in breach of this repository's code of conduct.
You will need to do this in your spring cloud config client code too right?
That's a question for the Spring Cloud team as Spring Cloud Config is managed as a separate project.
Comment From: warrenc5
Thanks for looking into this. No offence intended, just being jovial. Ok my mistake, I don't know why I posted it here then.. Too many tabs maybe :)
Comment From: warrenc5
I raised a bug here. https://github.com/spring-cloud/spring-cloud-config/issues/1680