Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Env vars de/serialization for formulation #486

Merged
merged 5 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public String toXmlString() throws GeneratorException {
*
* @return a String of the BoM
* @since 1.1.0
*
*/
@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.cyclonedx.model.component.crypto.enums.CertificationLevel;
Expand All @@ -16,7 +16,6 @@
import org.cyclonedx.model.component.crypto.enums.Mode;
import org.cyclonedx.model.component.crypto.enums.Padding;
import org.cyclonedx.model.component.crypto.enums.Primitive;
import org.cyclonedx.util.deserializer.CertificationLevelDeserializer;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand Down Expand Up @@ -44,8 +43,7 @@ public class AlgorithmProperties

private ImplementationPlatform implementationPlatform;

@JsonDeserialize(using = CertificationLevelDeserializer.class)
private CertificationLevel certificationLevel;
private List<CertificationLevel> certificationLevel;

private Mode mode;

Expand Down Expand Up @@ -97,11 +95,14 @@ public void setImplementationPlatform(final ImplementationPlatform implementatio
this.implementationPlatform = implementationPlatform;
}

public CertificationLevel getCertificationLevel() {
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "certificationLevel")
@JsonProperty("certificationLevel")
public List<CertificationLevel> getCertificationLevel() {
return certificationLevel;
}

public void setCertificationLevel(final CertificationLevel certificationLevel) {
public void setCertificationLevel(final List<CertificationLevel> certificationLevel) {
this.certificationLevel = certificationLevel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class AbstractType extends ExtensibleElement
private ResourceReferenceChoice source;
private ResourceReferenceChoice target;
private ResourceReferenceChoice resource;
private List<EnvVariableChoice> environmentVars;
private EnvironmentVars environmentVars;
private AttachmentText data;
private List<Property> properties;

Expand Down Expand Up @@ -44,13 +44,12 @@ public void setResource(final ResourceReferenceChoice resource) {
this.resource = resource;
}


@JacksonXmlElementWrapper(localName = "environmentVars")
public List<EnvVariableChoice> getEnvironmentVars() {
public EnvironmentVars getEnvironmentVars() {
return environmentVars;
}

public void setEnvironmentVars(final List<EnvVariableChoice> environmentVars) {
public void setEnvironmentVars(final EnvironmentVars environmentVars) {
this.environmentVars = environmentVars;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cyclonedx.model.formulation.common;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.cyclonedx.util.deserializer.EnvironmentVarsDeserializer;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonDeserialize(using = EnvironmentVarsDeserializer.class)
public class EnvironmentVars
{
private List<Object> choices;

public List<Object> getChoices() {
return choices;
}

public void setChoices(List<Object> choices) {
this.choices = choices;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,39 @@
*/
package org.cyclonedx.util.deserializer;

import java.util.ArrayList;
import java.io.IOException;
import java.util.List;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;

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 com.fasterxml.jackson.databind.DeserializationContext;
import org.cyclonedx.model.Property;
import org.cyclonedx.model.formulation.common.AbstractType;
import org.cyclonedx.model.formulation.common.EnvVariableChoice;
import org.cyclonedx.model.formulation.common.EnvironmentVars;
import org.cyclonedx.model.formulation.common.ResourceReferenceChoice;

public abstract class AbstractDataTypeDeserializer<T extends AbstractType>
extends JsonDeserializer<T> {

protected final ObjectMapper objectMapper = new ObjectMapper();

protected void setEnvironmentVars(final JsonNode node, AbstractType data) throws JsonProcessingException {
JsonNode nodes = node.get("environmentVars");
List<EnvVariableChoice> environmentVars = new ArrayList<>();

if (nodes != null) {
ArrayNode environmentVarsNode = DeserializerUtils.getArrayNode(nodes, objectMapper);
for (JsonNode envVarNode : environmentVarsNode) {
EnvVariableChoice envVar = objectMapper.treeToValue(envVarNode, EnvVariableChoice.class);
environmentVars.add(envVar);
}
}
private final EnvironmentVarsDeserializer environmentVarsDeserializer = new EnvironmentVarsDeserializer();

data.setEnvironmentVars(environmentVars);
protected void setEnvironmentVars(
final JsonNode node,
AbstractType data,
JsonParser jsonParser,
DeserializationContext ctxt) throws IOException
{
JsonNode nodes = node.get("environmentVars");
JsonParser nodeParser = nodes.traverse(jsonParser.getCodec());
EnvironmentVars envVar = environmentVarsDeserializer.deserialize(nodeParser, ctxt);
data.setEnvironmentVars(envVar);
}

protected void setReference(JsonNode node, String fieldName, AbstractType type) throws JsonProcessingException {
Expand Down

This file was deleted.

This file was deleted.

Loading