File tree Expand file tree Collapse file tree 4 files changed +55
-6
lines changed
src/main/java/org/cyclonedx Expand file tree Collapse file tree 4 files changed +55
-6
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ public ReleaseNotes() {}
6969 @ VersionFilter (Version .VERSION_14 )
7070 private Date timestamp ;
7171 private List <String > aliases ;
72+ @ JsonProperty ("tags" )
7273 private Tags tags ;
7374 private List <Resolves > resolves ;
7475 private List <Notes > notes ;
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ public class Service extends ExtensibleElement {
7575 @ VersionFilter (Version .VERSION_13 )
7676 private List <Property > properties ;
7777 @ VersionFilter (value = Version .VERSION_16 )
78+ @ JsonProperty ("tags" )
7879 private Tags tags ;
7980 private List <Service > services ;
8081 private ReleaseNotes releaseNotes ;
Original file line number Diff line number Diff line change 55import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
66import com .fasterxml .jackson .annotation .JsonInclude ;
77import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
8- import com .fasterxml .jackson .dataformat .xml .annotation .JacksonXmlElementWrapper ;
9- import com .fasterxml .jackson .dataformat .xml .annotation .JacksonXmlProperty ;
10- import org .cyclonedx .util .deserializer .StringListDeserializer ;
8+ import org .cyclonedx .util .deserializer .TagsDeserializer ;
119
1210@ JsonIgnoreProperties (ignoreUnknown = true )
1311@ JsonInclude (JsonInclude .Include .NON_EMPTY )
12+ @ JsonDeserialize (using = TagsDeserializer .class )
1413public class Tags
1514{
1615 private List <String > tags ;
1716
18- @ JacksonXmlElementWrapper (localName = "tags" )
19- @ JacksonXmlProperty (localName = "tag" )
20- @ JsonDeserialize (using = StringListDeserializer .class )
17+ public Tags () {
18+ }
19+
20+ public Tags (List <String > tags ){
21+ this .tags = tags ;
22+ }
23+
2124 public List <String > getTags () {
2225 return tags ;
2326 }
Original file line number Diff line number Diff line change 1+ package org .cyclonedx .util .deserializer ;
2+
3+ import java .io .IOException ;
4+ import java .util .ArrayList ;
5+ import java .util .List ;
6+
7+ import com .fasterxml .jackson .core .JsonParser ;
8+ import com .fasterxml .jackson .databind .DeserializationContext ;
9+ import com .fasterxml .jackson .databind .JsonDeserializer ;
10+ import com .fasterxml .jackson .databind .JsonNode ;
11+ import com .fasterxml .jackson .databind .ObjectMapper ;
12+ import com .fasterxml .jackson .databind .node .ArrayNode ;
13+ import org .cyclonedx .model .component .Tags ;
14+
15+ public class TagsDeserializer
16+ extends JsonDeserializer <Tags >
17+ {
18+
19+ private final ObjectMapper mapper = new ObjectMapper ();
20+ @ Override
21+ public Tags deserialize (JsonParser parser , DeserializationContext context ) throws IOException {
22+ JsonNode node = parser .getCodec ().readTree (parser );
23+
24+ if (node .has ("tag" )) {
25+ return parseNode (node .get ("tag" ));
26+ } else {
27+ return parseNode (node );
28+ }
29+ }
30+
31+ private Tags parseNode (JsonNode node ) {
32+ List <String > list = new ArrayList <>();
33+
34+ ArrayNode nodes = (node .isArray () ? (ArrayNode ) node : new ArrayNode (null ).add (node ));
35+ for (JsonNode tagNode : nodes ) {
36+ list .add (tagNode .asText ());
37+ }
38+
39+ if (!list .isEmpty ()) {
40+ return new Tags (list );
41+ }
42+ return null ;
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments