Format default platform version when serving metadata v2.1

See gh-1113
This commit is contained in:
Guillaume GERBAUD
2020-08-11 11:00:49 +02:00
committed by Stephane Nicoll
parent 9cdddc5a66
commit a202ce00ac
2 changed files with 9 additions and 2 deletions

View File

@@ -48,6 +48,7 @@ import org.springframework.util.StringUtils;
* A {@link InitializrMetadataJsonMapper} handling the metadata format for v2.
*
* @author Stephane Nicoll
* @author Guillaume Gerbaud
*/
public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMapper {
@@ -146,7 +147,10 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
single.put("type", capability.getType().getName());
DefaultMetadataElement defaultType = capability.getDefault();
if (defaultType != null) {
single.put("default", defaultType.getId());
ObjectNode defaultNode = valueMapper.apply(defaultType);
String defaultValue = (defaultNode.get("id") != null) ? defaultNode.get("id").textValue()
: defaultType.getId();
single.put("default", defaultValue);
}
ArrayNode values = nodeFactory.arrayNode();
values.addAll(capability.getContent().stream().map(valueMapper).collect(Collectors.toList()));

View File

@@ -102,7 +102,10 @@ class InitializrMetadataV21JsonMapperTests {
.addBootVersion("2.5.0-M2", false).addBootVersion("2.4.2", true).build();
String json = this.jsonMapper.write(metadata, null);
JsonNode result = objectMapper.readTree(json);
JsonNode versions = result.get("bootVersion").get("values");
JsonNode bootVersion = result.get("bootVersion");
JsonNode defaultNode = bootVersion.get("default");
assertThat(defaultNode.textValue()).isEqualTo("2.4.2.RELEASE");
JsonNode versions = bootVersion.get("values");
assertThat(versions).hasSize(3);
assertVersionMetadata(versions.get(0), "2.5.0.BUILD-SNAPSHOT", "2.5.0-SNAPSHOT");
assertVersionMetadata(versions.get(1), "2.5.0.M2", "2.5.0-M2");