From 4e08303903684fb8c692a347e7cb954eb17aa869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Thu, 28 Nov 2024 22:39:23 +0100 Subject: [PATCH] Add default value handling again --- .../io/fabric8/crdv2/generator/AbstractJsonSchema.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/AbstractJsonSchema.java b/crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/AbstractJsonSchema.java index cd60034169..3b7202b0eb 100644 --- a/crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/AbstractJsonSchema.java +++ b/crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/AbstractJsonSchema.java @@ -314,7 +314,15 @@ public PropertyMetadata(JsonSchema value, BeanProperty beanProperty) { // TODO: should the following be deprecated? required = beanProperty.getAnnotation(Required.class) != null; - defaultValue = ofNullable(beanProperty.getAnnotation(Default.class)).map(Default::value).orElse(defaultValue); + + if (beanProperty.getMetadata().getDefaultValue() != null) { + defaultValue = toTargetType(beanProperty.getType(), beanProperty.getMetadata().getDefaultValue()); + } else if (ofNullable(beanProperty.getAnnotation(Default.class)).map(Default::value).isPresent()) { + defaultValue = toTargetType(beanProperty.getType(), + ofNullable(beanProperty.getAnnotation(Default.class)).map(Default::value).get()); + } else { + defaultValue = null; + } } private void setMinMax(BeanProperty beanProperty,