/** * Registers a Custom Resource Definition Kind */ public static void registerCustomKind(String apiVersion, String kind, Class<? extends KubernetesResource> clazz) { MAP.put(getKey(apiVersion, kind), clazz); }
/** * Return a string representation of the key of the type: <version>#<kind>. */ private static final String getKey(ObjectNode node) { JsonNode apiVersion = node.get(API_VERSION); JsonNode kind = node.get(KIND); return getKey(apiVersion != null ? apiVersion.textValue() : null, kind != null ? kind.textValue() : null); }
@Override public KubernetesResource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectNode node = jp.readValueAsTree(); String key = getKey(node); if (key != null) { Class<? extends KubernetesResource> resourceType = getTypeForKey(key); if (resourceType == null) { throw ctxt.mappingException("No resource type found for:" + key); } else { return jp.getCodec().treeToValue(node, resourceType); } } return null; }