From 27bbb20debec23035c452ae56f4931dc6f24f699 Mon Sep 17 00:00:00 2001 From: StephenOTT Date: Fri, 3 May 2019 06:41:24 -0400 Subject: [PATCH] Jackson StixInstantModule refactor --- README.md | 1 - pom.xml | 2 +- .../stix/common/StixCommonProperties.java | 4 --- .../stix/common/StixModified.java | 1 - .../WindowsPeBinaryFileExtensionExt.java | 3 -- .../stix/coo/objects/DirectoryCoo.java | 5 --- .../stix/coo/objects/EmailMessageCoo.java | 3 -- .../stix/coo/objects/FileCoo.java | 5 --- .../stix/coo/objects/NetworkTrafficCoo.java | 4 --- .../stix/coo/objects/ProcessCoo.java | 3 -- .../stix/coo/objects/UserAccountCoo.java | 7 ---- .../coo/objects/WindowsRegistryKeyCoo.java | 3 -- .../stix/coo/objects/X509CertificateCoo.java | 4 --- .../stix/coo/types/X509v3ExtensionsObj.java | 4 --- .../json/StixOptionalInstantDeserializer.java | 26 -------------- .../json/StixOptionalInstantSerializer.java | 34 ------------------- .../digitalstate/stix/json/StixParsers.java | 2 ++ .../stix/sdo/objects/CampaignSdo.java | 4 --- .../stix/sdo/objects/IndicatorSdo.java | 6 ---- .../stix/sdo/objects/IntrusionSetSdo.java | 4 --- .../stix/sdo/objects/ObservedDataSdo.java | 2 -- .../stix/sdo/objects/ReportSdo.java | 1 - .../stix/sro/objects/SightingSro.java | 4 --- 23 files changed, 3 insertions(+), 129 deletions(-) delete mode 100644 src/main/java/io/digitalstate/stix/json/StixOptionalInstantDeserializer.java delete mode 100644 src/main/java/io/digitalstate/stix/json/StixOptionalInstantSerializer.java diff --git a/README.md b/README.md index 7a44924..504f824 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,6 @@ class SomeClass { Optional getCreatedByRef(); @NotNull - @JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class) @JsonProperty("created") @Value.Default @Redactable(useMask = true) diff --git a/pom.xml b/pom.xml index ce44c2f..4c6c8c1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.digitalstate.stix stix - v0.8.1 + v0.8.2 jar STIX 2 diff --git a/src/main/java/io/digitalstate/stix/common/StixCommonProperties.java b/src/main/java/io/digitalstate/stix/common/StixCommonProperties.java index 016f926..712ffd7 100644 --- a/src/main/java/io/digitalstate/stix/common/StixCommonProperties.java +++ b/src/main/java/io/digitalstate/stix/common/StixCommonProperties.java @@ -3,12 +3,9 @@ import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.bundle.BundleableObject; import io.digitalstate.stix.datamarkings.GranularMarkingDm; import io.digitalstate.stix.datamarkings.MarkingDefinitionDm; -import io.digitalstate.stix.json.StixInstantDeserializer; -import io.digitalstate.stix.json.StixInstantSerializer; import io.digitalstate.stix.json.StixParsers; import io.digitalstate.stix.json.converters.dehydrated.DomainObjectOptionalConverter; import io.digitalstate.stix.json.converters.dehydrated.MarkingDefinitionSetConverter; @@ -71,7 +68,6 @@ default boolean getHydrated(){ Optional getCreatedByRef(); @NotNull - @JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class) @JsonProperty("created") @JsonPropertyDescription("The created property represents the time at which the first version of this object was created. The timstamp value MUST be precise to the nearest millisecond.") @Value.Default diff --git a/src/main/java/io/digitalstate/stix/common/StixModified.java b/src/main/java/io/digitalstate/stix/common/StixModified.java index b70bb23..bfe1b09 100644 --- a/src/main/java/io/digitalstate/stix/common/StixModified.java +++ b/src/main/java/io/digitalstate/stix/common/StixModified.java @@ -21,7 +21,6 @@ public interface StixModified { @NotNull @JsonProperty("modified") @JsonPropertyDescription("The modified property represents the time that this particular version of the object was created. The timstamp value MUST be precise to the nearest millisecond.") - @JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class) @Value.Default @Redactable default StixInstant getModified(){ diff --git a/src/main/java/io/digitalstate/stix/coo/extension/types/WindowsPeBinaryFileExtensionExt.java b/src/main/java/io/digitalstate/stix/coo/extension/types/WindowsPeBinaryFileExtensionExt.java index e149c16..d7eb470 100644 --- a/src/main/java/io/digitalstate/stix/coo/extension/types/WindowsPeBinaryFileExtensionExt.java +++ b/src/main/java/io/digitalstate/stix/coo/extension/types/WindowsPeBinaryFileExtensionExt.java @@ -8,8 +8,6 @@ import io.digitalstate.stix.coo.objects.FileCoo; import io.digitalstate.stix.coo.types.WindowsPeOptionalHeaderObj; import io.digitalstate.stix.coo.types.WindowsPeSectionObj; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.coo.allowedparents.AllowedParents; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.contraints.hashingvocab.HashingVocab; @@ -68,7 +66,6 @@ public interface WindowsPeBinaryFileExtensionExt extends CyberObservableExtensio @JsonProperty("time_date_stamp") @JsonPropertyDescription("Specifies the time when the PE binary was created. The timestamp value MUST BE precise to the second.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getTimeDateStamp(); @JsonProperty("pointer_to_symbol_table_hex") diff --git a/src/main/java/io/digitalstate/stix/coo/objects/DirectoryCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/DirectoryCoo.java index 0b3ab5a..4eaccee 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/DirectoryCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/DirectoryCoo.java @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.groups.DefaultValuesProcessor; import org.immutables.serial.Serial; @@ -46,17 +44,14 @@ public interface DirectoryCoo extends CyberObservableObject { Optional<@Pattern(regexp = "^[a-zA-Z0-9/\\.+_:-]{2,250}$") String> getPathEnc(); - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("created") @JsonPropertyDescription("Specifies the date/time the directory was created.") Optional getCreated(); - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("modified") @JsonPropertyDescription("Specifies the date/time the directory was last written to/modified.") Optional getModified(); - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("accessed") @JsonPropertyDescription("Specifies the date/time the directory was last accessed.") Optional getAccessed(); diff --git a/src/main/java/io/digitalstate/stix/coo/objects/EmailMessageCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/EmailMessageCoo.java index ce86da5..9ae00d9 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/EmailMessageCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/EmailMessageCoo.java @@ -6,8 +6,6 @@ import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; import io.digitalstate.stix.coo.types.MimePartTypeObj; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.groups.DefaultValuesProcessor; @@ -43,7 +41,6 @@ public interface EmailMessageCoo extends CyberObservableObject { @NotNull boolean isMultipart(); - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("date") @JsonPropertyDescription("Specifies the date/time that the email message was sent.") Optional getDate(); diff --git a/src/main/java/io/digitalstate/stix/coo/objects/FileCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/FileCoo.java index 51be8df..defe256 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/FileCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/FileCoo.java @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.contraints.hashingvocab.HashingVocab; @@ -75,17 +73,14 @@ public interface FileCoo extends CyberObservableObject { @JsonProperty("created") @JsonPropertyDescription("Specifies the date/time the file was created.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getCreated(); @JsonProperty("modified") @JsonPropertyDescription("Specifies the date/time the file was last written to/modified.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getModified(); @JsonProperty("accessed") @JsonPropertyDescription("Specifies the date/time the file was last accessed.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getAccessed(); @JsonProperty("parent_directory_ref") diff --git a/src/main/java/io/digitalstate/stix/coo/objects/NetworkTrafficCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/NetworkTrafficCoo.java index aa6f016..d283a0d 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/NetworkTrafficCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/NetworkTrafficCoo.java @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.groups.DefaultValuesProcessor; import org.hibernate.validator.constraints.Range; @@ -42,12 +40,10 @@ public interface NetworkTrafficCoo extends CyberObservableObject { @JsonProperty("start") @JsonPropertyDescription("Specifies the date/time the network traffic was initiated, if known.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getStart(); @JsonProperty("end") @JsonPropertyDescription("Specifies the date/time the network traffic ended, if known.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getEnd(); @JsonProperty("is_active") diff --git a/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java index b29a1b9..ec81bcd 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.groups.DefaultValuesProcessor; @@ -56,7 +54,6 @@ public interface ProcessCoo extends CyberObservableObject { @JsonProperty("created") @JsonPropertyDescription("Specifies the date/time at which the process was created.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getCreated(); @JsonProperty("cwd") diff --git a/src/main/java/io/digitalstate/stix/coo/objects/UserAccountCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/UserAccountCoo.java index 07367b1..5586cde 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/UserAccountCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/UserAccountCoo.java @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.contraints.vocab.Vocab; import io.digitalstate.stix.validation.groups.DefaultValuesProcessor; @@ -78,27 +76,22 @@ public interface UserAccountCoo extends CyberObservableObject { @JsonProperty("account_created") @JsonPropertyDescription("Specifies when the account was created.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getAccountCreated(); @JsonProperty("account_expires") @JsonPropertyDescription("Specifies the expiration date of the account.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getAccountExpires(); @JsonProperty("password_last_changed") @JsonPropertyDescription("Specifies when the account password was last changed.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getPasswordLastChanged(); @JsonProperty("account_first_login") @JsonPropertyDescription("Specifies when the account was first accessed.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getAccountFirstLogin(); @JsonProperty("account_last_login") @JsonPropertyDescription("Specifies when the account was last accessed.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getAccountLastLogin(); } diff --git a/src/main/java/io/digitalstate/stix/coo/objects/WindowsRegistryKeyCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/WindowsRegistryKeyCoo.java index 8a2a664..49017a9 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/WindowsRegistryKeyCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/WindowsRegistryKeyCoo.java @@ -6,8 +6,6 @@ import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; import io.digitalstate.stix.coo.types.WindowsRegistryValueObj; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.groups.DefaultValuesProcessor; import org.immutables.serial.Serial; @@ -48,7 +46,6 @@ public interface WindowsRegistryKeyCoo extends CyberObservableObject { @JsonProperty("modified") @JsonPropertyDescription("Specifies the last date/time that the registry key was modified.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getModified(); //@TODO Must be of type user-account diff --git a/src/main/java/io/digitalstate/stix/coo/objects/X509CertificateCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/X509CertificateCoo.java index 9e9f529..ed9672c 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/X509CertificateCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/X509CertificateCoo.java @@ -6,8 +6,6 @@ import io.digitalstate.stix.common.StixInstant; import io.digitalstate.stix.coo.CyberObservableObject; import io.digitalstate.stix.coo.types.X509v3ExtensionsObj; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.contraints.hashingvocab.HashingVocab; @@ -70,12 +68,10 @@ public interface X509CertificateCoo extends CyberObservableObject { @JsonProperty("validity_not_before") @JsonPropertyDescription("Specifies the date on which the certificate validity period begins.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getValidityNotBefore(); @JsonProperty("validity_not_after") @JsonPropertyDescription("Specifies the date on which the certificate validity period ends.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getValidityNotAfter(); @JsonProperty("subject") diff --git a/src/main/java/io/digitalstate/stix/coo/types/X509v3ExtensionsObj.java b/src/main/java/io/digitalstate/stix/coo/types/X509v3ExtensionsObj.java index 1a38e85..0a4d382 100644 --- a/src/main/java/io/digitalstate/stix/coo/types/X509v3ExtensionsObj.java +++ b/src/main/java/io/digitalstate/stix/coo/types/X509v3ExtensionsObj.java @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixCustomProperties; import io.digitalstate.stix.common.StixInstant; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.validation.GenericValidation; import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule; import org.immutables.serial.Serial; @@ -90,12 +88,10 @@ public interface X509v3ExtensionsObj extends GenericValidation, StixCustomProper @JsonProperty("private_key_usage_period_not_before") @JsonPropertyDescription("Specifies the date on which the validity period begins for the key, if it is different from the validity period of the certificate.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getPrivateKeyUsagePeriodNotBefore(); @JsonProperty("private_key_usage_period_not_after") @JsonPropertyDescription("Specifies the date on which the validity period ends for the key, if it is different from the validity period of the certificate.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) Optional getPrivateKeyUsagePeriodNotAfter(); @JsonProperty("certificate_policies") diff --git a/src/main/java/io/digitalstate/stix/json/StixOptionalInstantDeserializer.java b/src/main/java/io/digitalstate/stix/json/StixOptionalInstantDeserializer.java deleted file mode 100644 index 16e4fe6..0000000 --- a/src/main/java/io/digitalstate/stix/json/StixOptionalInstantDeserializer.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.digitalstate.stix.json; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import io.digitalstate.stix.common.StixInstant; - -import java.io.IOException; -import java.util.Optional; - -public class StixOptionalInstantDeserializer extends StdDeserializer> { - - public StixOptionalInstantDeserializer(){ - this(null); - } - - public StixOptionalInstantDeserializer(Class vc) { - super(vc); - } - - @Override - public Optional deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { - return Optional.of(StixInstant.parse(p.getText())); - } -} diff --git a/src/main/java/io/digitalstate/stix/json/StixOptionalInstantSerializer.java b/src/main/java/io/digitalstate/stix/json/StixOptionalInstantSerializer.java deleted file mode 100644 index e03afd8..0000000 --- a/src/main/java/io/digitalstate/stix/json/StixOptionalInstantSerializer.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.digitalstate.stix.json; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import io.digitalstate.stix.common.StixInstant; - -import java.io.IOException; -import java.util.Optional; - -public class StixOptionalInstantSerializer extends StdSerializer> { - - public StixOptionalInstantSerializer() { - this(null); - } - - public StixOptionalInstantSerializer(Class> t) { - super(t); - } - - @Override - public boolean isEmpty(SerializerProvider provider, Optional value) { - return !value.isPresent(); - } - - @Override - public void serialize(Optional value, JsonGenerator gen, SerializerProvider provider) throws IOException { - if (!value.isPresent()){ - throw new IllegalStateException(); - } else { - gen.writeString(value.get().toString()); - } - } -} diff --git a/src/main/java/io/digitalstate/stix/json/StixParsers.java b/src/main/java/io/digitalstate/stix/json/StixParsers.java index 75e8008..c8ac597 100644 --- a/src/main/java/io/digitalstate/stix/json/StixParsers.java +++ b/src/main/java/io/digitalstate/stix/json/StixParsers.java @@ -23,6 +23,7 @@ import javax.validation.ValidationException; import java.io.IOException; +import java.util.Optional; public class StixParsers { @@ -43,6 +44,7 @@ public static ObjectMapper generateJsonMapperBase() { public static ObjectMapper getJsonMapper(boolean withSubTypeMappings, NamedType... additionalNamedTypes) { //@TODO Add config to only serialize/deserialize that have @JsonProperty() annotation if (withSubTypeMappings) { + jsonMapper.registerModule(generateStixInstantModule()); return registerBundleMapperSubTypes(jsonMapper, additionalNamedTypes); } else { return jsonMapper; diff --git a/src/main/java/io/digitalstate/stix/sdo/objects/CampaignSdo.java b/src/main/java/io/digitalstate/stix/sdo/objects/CampaignSdo.java index 1bee3bc..5a63ee1 100644 --- a/src/main/java/io/digitalstate/stix/sdo/objects/CampaignSdo.java +++ b/src/main/java/io/digitalstate/stix/sdo/objects/CampaignSdo.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.redaction.Redactable; import io.digitalstate.stix.sdo.DomainObject; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; @@ -58,7 +56,6 @@ public interface CampaignSdo extends DomainObject { @Redactable Set getAliases(); - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("first_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY) @JsonPropertyDescription("The time that this Campaign was first seen.") @@ -66,7 +63,6 @@ public interface CampaignSdo extends DomainObject { Optional getFirstSeen(); //@TODO add support to ensure that Last Seen is AFTER the First Seen value - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("last_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY) @JsonPropertyDescription("The time that this Campaign was last seen.") @Redactable diff --git a/src/main/java/io/digitalstate/stix/sdo/objects/IndicatorSdo.java b/src/main/java/io/digitalstate/stix/sdo/objects/IndicatorSdo.java index 742790b..5493156 100644 --- a/src/main/java/io/digitalstate/stix/sdo/objects/IndicatorSdo.java +++ b/src/main/java/io/digitalstate/stix/sdo/objects/IndicatorSdo.java @@ -4,10 +4,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; -import io.digitalstate.stix.json.StixInstantDeserializer; -import io.digitalstate.stix.json.StixInstantSerializer; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.redaction.Redactable; import io.digitalstate.stix.sdo.DomainObject; import io.digitalstate.stix.sdo.types.KillChainPhaseType; @@ -73,13 +69,11 @@ public interface IndicatorSdo extends DomainObject { @NotNull @JsonProperty("valid_from") @JsonPropertyDescription("The time from which this indicator should be considered valuable intelligence.") - @JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class) @Redactable(useMask = true) StixInstant getValidFrom(); @JsonProperty("valid_until") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY) @JsonPropertyDescription("The time at which this indicator should no longer be considered valuable intelligence.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @Redactable Optional getValidUntil(); diff --git a/src/main/java/io/digitalstate/stix/sdo/objects/IntrusionSetSdo.java b/src/main/java/io/digitalstate/stix/sdo/objects/IntrusionSetSdo.java index ea57c9a..41ac603 100644 --- a/src/main/java/io/digitalstate/stix/sdo/objects/IntrusionSetSdo.java +++ b/src/main/java/io/digitalstate/stix/sdo/objects/IntrusionSetSdo.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.redaction.Redactable; import io.digitalstate.stix.sdo.DomainObject; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; @@ -62,13 +60,11 @@ public interface IntrusionSetSdo extends DomainObject { @JsonProperty("first_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY) @JsonPropertyDescription("The time that this Intrusion Set was first seen.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @Redactable Optional getFirstSeen(); @JsonProperty("last_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY) @JsonPropertyDescription("The time that this Intrusion Set was last seen.") - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @Redactable Optional getLastSeen(); diff --git a/src/main/java/io/digitalstate/stix/sdo/objects/ObservedDataSdo.java b/src/main/java/io/digitalstate/stix/sdo/objects/ObservedDataSdo.java index c80a63e..1a3169d 100644 --- a/src/main/java/io/digitalstate/stix/sdo/objects/ObservedDataSdo.java +++ b/src/main/java/io/digitalstate/stix/sdo/objects/ObservedDataSdo.java @@ -46,14 +46,12 @@ public interface ObservedDataSdo extends DomainObject { @NotNull @JsonProperty("first_observed") @JsonPropertyDescription("The beginning of the time window that the data was observed during.") - @JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class) @Redactable(useMask = true) StixInstant getFirstObserved(); @NotNull @JsonProperty("last_observed") @JsonPropertyDescription("The end of the time window that the data was observed during.") - @JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class) @Redactable(useMask = true) StixInstant getLastObserved(); diff --git a/src/main/java/io/digitalstate/stix/sdo/objects/ReportSdo.java b/src/main/java/io/digitalstate/stix/sdo/objects/ReportSdo.java index 451a1e1..4edf9a5 100644 --- a/src/main/java/io/digitalstate/stix/sdo/objects/ReportSdo.java +++ b/src/main/java/io/digitalstate/stix/sdo/objects/ReportSdo.java @@ -66,7 +66,6 @@ public interface ReportSdo extends DomainObject { @NotNull @JsonProperty("published") @JsonPropertyDescription("The date that this report object was officially published by the creator of this report.") - @JsonSerialize(using = StixInstantSerializer.class) @JsonDeserialize(using = StixInstantDeserializer.class) @Redactable(useMask = true) StixInstant getPublished(); diff --git a/src/main/java/io/digitalstate/stix/sro/objects/SightingSro.java b/src/main/java/io/digitalstate/stix/sro/objects/SightingSro.java index 8f90bf2..1a36b11 100644 --- a/src/main/java/io/digitalstate/stix/sro/objects/SightingSro.java +++ b/src/main/java/io/digitalstate/stix/sro/objects/SightingSro.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.common.StixInstant; -import io.digitalstate.stix.json.StixOptionalInstantDeserializer; -import io.digitalstate.stix.json.StixOptionalInstantSerializer; import io.digitalstate.stix.json.converters.dehydrated.DomainObjectConverter; import io.digitalstate.stix.redaction.Redactable; import io.digitalstate.stix.sdo.DomainObject; @@ -44,13 +42,11 @@ @Redactable public interface SightingSro extends RelationshipObject { - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("first_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY) @JsonPropertyDescription("The beginning of the time window during which the SDO referenced by the sighting_of_ref property was sighted.") @Redactable Optional getFirstSeen(); - @JsonSerialize(using = StixOptionalInstantSerializer.class) @JsonDeserialize(using = StixOptionalInstantDeserializer.class) @JsonProperty("last_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY) @JsonPropertyDescription("The end of the time window during which the SDO referenced by the sighting_of_ref property was sighted.") @Redactable