Skip to content

Commit 4b9d2da

Browse files
fhussonnoisclaude
andcommitted
fix(core): normalize apiVersion during deserialization for backward compatibility
When a YAML file uses an old apiVersion (e.g., v1beta2) and no exact match exists in the deserializer mapping, the LatestApiVersionResourceTypeResolver resolves the correct class. However, the deserialized resource retained the old apiVersion from the YAML, causing controller matching to fail since controllers now only support v1. This fix normalizes the apiVersion field in the JSON node before deserialization when the type was resolved by a fallback resolver, ensuring the resource carries the canonical version of the resolved class. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c068fc9 commit 4b9d2da

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

core/src/main/java/io/streamthoughts/jikkou/core/resource/ResourceDeserializer.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.fasterxml.jackson.databind.DeserializationContext;
1111
import com.fasterxml.jackson.databind.JsonDeserializer;
1212
import com.fasterxml.jackson.databind.JsonNode;
13+
import com.fasterxml.jackson.databind.node.ObjectNode;
1314
import io.streamthoughts.jikkou.core.annotation.Reflectable;
1415
import io.streamthoughts.jikkou.core.models.Resource;
1516
import io.streamthoughts.jikkou.core.models.ResourceType;
@@ -53,6 +54,7 @@ public Resource deserialize(JsonParser parser, DeserializationContext deserializ
5354

5455
private static Resource fromObjectNode(JsonParser jp, JsonNode node) throws IOException {
5556
Class<? extends Resource> resourceType = null;
57+
boolean resolvedByFallback = false;
5658

5759
ResourceType key = ResourceType.of(node);
5860

@@ -79,6 +81,7 @@ private static Resource fromObjectNode(JsonParser jp, JsonNode node) throws IOEx
7981
for (ResourceTypeResolver r : resolvers) {
8082
resourceType = r.resolvesType(node);
8183
if (resourceType != null) {
84+
resolvedByFallback = true;
8285
break;
8386
}
8487
}
@@ -97,10 +100,18 @@ private static Resource fromObjectNode(JsonParser jp, JsonNode node) throws IOEx
97100
}
98101
return jp.getCodec().treeToValue(node, GenericResource.class);
99102
} else if (Resource.class.isAssignableFrom(resourceType)) {
103+
String resolvedApiVersion = Resource.getApiVersion(resourceType);
100104
LOG.debug("Read specific resource for apiVersion={}, kind={}.",
101-
Resource.getApiVersion(resourceType),
105+
resolvedApiVersion,
102106
Resource.getKind(resourceType)
103107
);
108+
// Normalize the apiVersion in the node when the type was resolved by a fallback
109+
// resolver (e.g., LatestApiVersionResourceTypeResolver). This ensures that the
110+
// deserialized resource carries the canonical apiVersion of the resolved class,
111+
// not the (potentially outdated) version from the YAML input.
112+
if (resolvedByFallback && resolvedApiVersion != null && node.isObject()) {
113+
((ObjectNode) node).put("apiVersion", resolvedApiVersion);
114+
}
104115
return jp.getCodec().treeToValue(node, resourceType);
105116
}
106117
LOG.warn("Failed get resource type from JsonNode");

0 commit comments

Comments
 (0)