Skip to content

Commit d251b99

Browse files
nosansnicoll
authored andcommitted
Use ObjectNode for building ImagePlatform JSON
See gh-48100 Signed-off-by: Dmytro Nosan <[email protected]> Closes gh-48100
1 parent b6460ea commit d251b99

File tree

1 file changed

+8
-9
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import java.util.Objects;
2020

21+
import com.fasterxml.jackson.databind.node.ObjectNode;
22+
23+
import org.springframework.boot.buildpack.platform.json.SharedObjectMapper;
2124
import org.springframework.util.Assert;
2225
import org.springframework.util.StringUtils;
2326

@@ -105,19 +108,15 @@ public static ImagePlatform from(Image image) {
105108
* @return the JSON string
106109
*/
107110
public String toJson() {
108-
StringBuilder json = new StringBuilder("{");
109-
json.append(jsonPair("os", this.os));
111+
ObjectNode json = SharedObjectMapper.get().createObjectNode();
112+
json.put("os", this.os);
110113
if (StringUtils.hasText(this.architecture)) {
111-
json.append(",").append(jsonPair("architecture", this.architecture));
114+
json.put("architecture", this.architecture);
112115
}
113116
if (StringUtils.hasText(this.variant)) {
114-
json.append(",").append(jsonPair("variant", this.variant));
117+
json.put("variant", this.variant);
115118
}
116-
return json.append("}").toString();
117-
}
118-
119-
private String jsonPair(String name, String value) {
120-
return "\"%s\":\"%s\"".formatted(name, value);
119+
return json.toString();
121120
}
122121

123122
}

0 commit comments

Comments
 (0)