-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tags Support , deprecated manufacture in Component and Metadata (#…
…381) Signed-off-by: Alex Alzate <aalzate@sonatype.com>
- Loading branch information
Showing
7 changed files
with
144 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.cyclonedx.model.component; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import org.cyclonedx.util.deserializer.TagsDeserializer; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonDeserialize(using = TagsDeserializer.class) | ||
public class Tags | ||
{ | ||
private List<String> tags; | ||
|
||
public Tags() { | ||
} | ||
|
||
public Tags(List<String> tags){ | ||
this.tags = tags; | ||
} | ||
|
||
@JacksonXmlElementWrapper(localName = "tags") | ||
@JacksonXmlProperty(localName = "tag") | ||
@JsonProperty("tags") | ||
public List<String> getTags() { | ||
return tags; | ||
} | ||
|
||
public void setTags(final List<String> tags) { | ||
this.tags = tags; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/cyclonedx/util/deserializer/TagsDeserializer.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,44 @@ | ||
package org.cyclonedx.util.deserializer; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import org.cyclonedx.model.component.Tags; | ||
|
||
public class TagsDeserializer | ||
extends JsonDeserializer<Tags> | ||
{ | ||
|
||
private final ObjectMapper mapper = new ObjectMapper(); | ||
@Override | ||
public Tags deserialize(JsonParser parser, DeserializationContext context) throws IOException { | ||
JsonNode node = parser.getCodec().readTree(parser); | ||
|
||
if(node.has("tag")) { | ||
return parseNode(node.get("tag")); | ||
} else { | ||
return parseNode(node); | ||
} | ||
} | ||
|
||
private Tags parseNode(JsonNode node) { | ||
List<String> list = new ArrayList<>(); | ||
|
||
ArrayNode nodes = (node.isArray() ? (ArrayNode) node : new ArrayNode(null).add(node)); | ||
for (JsonNode tagNode : nodes) { | ||
list.add(tagNode.asText()); | ||
} | ||
|
||
if(!list.isEmpty()) { | ||
return new Tags(list); | ||
} | ||
return null; | ||
} | ||
} |
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