-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core,webserver): store labels as a list instead of a map
- Loading branch information
1 parent
16ac515
commit 007142c
Showing
20 changed files
with
190 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.kestra.core.models; | ||
|
||
public record Label(String key, String value) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/java/io/kestra/core/serializers/ListOrMapOfLabelDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.kestra.core.serializers; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.deser.ResolvableDeserializer; | ||
import io.kestra.core.models.Label; | ||
import io.kestra.core.utils.LabelUtils; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This deserializer is for historical purpose, labels was first a map but has been updated to a List of Label so | ||
* this deserializer allows using both types. | ||
*/ | ||
public class ListOrMapOfLabelDeserializer extends JsonDeserializer<List<Label>> implements ResolvableDeserializer { | ||
@Override | ||
public List<Label> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
if (p.hasToken(JsonToken.VALUE_NULL)) { | ||
return null; | ||
} | ||
else if (p.hasToken(JsonToken.START_ARRAY)) { | ||
// deserialize as list | ||
List<Map<String, String>> ret = ctxt.readValue(p, List.class); | ||
return ret.stream().map(map -> new Label(map.get("key"), map.get("value"))).toList(); | ||
} | ||
else if (p.hasToken(JsonToken.START_OBJECT)) { | ||
// deserialize as map | ||
Map<String, String> ret = ctxt.readValue(p, Map.class); | ||
return LabelUtils.from(ret); | ||
} | ||
throw new IllegalArgumentException("Unable to deserialize value as it's neither an object neither an array"); | ||
} | ||
|
||
@Override | ||
public void resolve(DeserializationContext ctxt) throws JsonMappingException {} | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/java/io/kestra/core/serializers/ListOrMapOfLabelSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.kestra.core.serializers; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This serializer is for historical purpose, labels was first a map but has been updated to a List of Label so | ||
* this serializer allows using both types. | ||
*/ | ||
public class ListOrMapOfLabelSerializer extends JsonSerializer<Object> { | ||
@Override | ||
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
if (value == null) { | ||
gen.writeNull(); | ||
} | ||
else if (value instanceof List) { | ||
serializers.findValueSerializer(List.class).serialize(value, gen, serializers); | ||
} | ||
else if (value instanceof Map) { | ||
serializers.findValueSerializer(Map.class).serialize(value, gen, serializers); | ||
} | ||
else { | ||
throw new IllegalArgumentException("Unable to serialize value as it's neither a map nor a list"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.