Skip to content

Commit

Permalink
fix: Add support for Java 8 date/time types
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Oct 10, 2023
1 parent ba024c6 commit 6cff8c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions FortifyVulnerabilityExporter-plugin-to-json/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ dependencies {
compileOnly 'com.fasterxml.jackson.core:jackson-core'
compileOnly 'com.fasterxml.jackson.core:jackson-databind'
compileOnly 'commons-collections:commons-collections'
// Required for Java 8 date/time handling
compileOnly 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
compileOnly 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fortify.util.rest.json.JSONMap;
import com.fortify.util.spring.expression.ExpressionMapToJSONMapEvaluator;
import com.fortify.util.spring.expression.TemplateExpressionMap;
Expand All @@ -49,7 +50,7 @@
*
*/
public class JsonFormatter implements Consumer<IVulnerabilityAccessor> {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final ObjectMapper MAPPER = createObjectMapper();
private final JsonFormatterConfig formatterConfig;
private final Map<String, VulnerabilityMapper> vulnerabilityMappers;
private final Map<String, JSONMap> contextObjects;
Expand Down Expand Up @@ -154,6 +155,12 @@ private Map<String, Object> createEvaluationInput() {
return result;
}

private static final ObjectMapper createObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
}

private static final int size(Map<?, ?> map) {
return map==null ? 0 : map.size();
}
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ allprojects {
// Spring Boot version is compatible with snakeyaml 2.0, which doesn't have
// any known vulnerabilities, so we override the version here.
implementation 'org.yaml:snakeyaml:2.0'
// Required for Java 8 date/time handling
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
}
}
}
Expand Down

0 comments on commit 6cff8c8

Please sign in to comment.