Browse Source

Merge pull request #48100 from nosan

* pr/48100:
  Use ObjectNode for building ImagePlatform JSON

Closes gh-48100
pull/48297/head
Stéphane Nicoll 1 month ago
parent
commit
fc826218b4
  1. 17
      spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImagePlatform.java

17
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImagePlatform.java

@ -18,6 +18,9 @@ package org.springframework.boot.buildpack.platform.docker.type;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.boot.buildpack.platform.json.SharedObjectMapper;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -105,19 +108,15 @@ public class ImagePlatform {
* @return the JSON string * @return the JSON string
*/ */
public String toJson() { public String toJson() {
StringBuilder json = new StringBuilder("{"); ObjectNode json = SharedObjectMapper.get().createObjectNode();
json.append(jsonPair("os", this.os)); json.put("os", this.os);
if (StringUtils.hasText(this.architecture)) { if (StringUtils.hasText(this.architecture)) {
json.append(",").append(jsonPair("architecture", this.architecture)); json.put("architecture", this.architecture);
} }
if (StringUtils.hasText(this.variant)) { if (StringUtils.hasText(this.variant)) {
json.append(",").append(jsonPair("variant", this.variant)); json.put("variant", this.variant);
} }
return json.append("}").toString(); return json.toString();
}
private String jsonPair(String name, String value) {
return "\"%s\":\"%s\"".formatted(name, value);
} }
} }

Loading…
Cancel
Save