Skip to content

Commit

Permalink
Remove InstantSerializer from methods as it was causing json conversi…
Browse files Browse the repository at this point in the history
…on issues
  • Loading branch information
StephenOTT committed Jan 11, 2019
1 parent f8cb78f commit 1704d7f
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.digitalstate.stix</groupId>
<artifactId>stix</artifactId>
<version>v0.5.3</version>
<version>v0.5.4</version>
<packaging>jar</packaging>

<name>STIX 2</name>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/digitalstate/stix/bundle/BundleObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
@DefaultTypeValue(value = "bundle", groups = {DefaultValuesProcessor.class})
@JsonTypeName("bundle")
@Value.Style(typeImmutable = "Bundle", validationMethod = Value.Style.ValidationMethod.NONE, additionalJsonAnnotations = {JsonTypeName.class})
@JsonSerialize(as = Bundle.class)
@JsonDeserialize(builder = Bundle.Builder.class)
@JsonSerialize(as = Bundle.class) @JsonDeserialize(builder = Bundle.Builder.class)
@JsonPropertyOrder({"type", "id", "spec_version", "objects"})
public interface BundleObject extends GenericValidation, Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ default boolean getHydrated(){
Optional<IdentitySdo> getCreatedByRef();

@NotNull
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@JsonProperty("created")
@Value.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public interface StixModified {

@NotNull
@JsonProperty("modified")
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@Value.Default
@Redactable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ public interface CampaignSdo extends DomainObject {
@Redactable
Set<String> getAliases();

@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@JsonProperty("first_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@Redactable
Optional<Instant> getFirstSeen();

@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@JsonProperty("last_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@Redactable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public interface IndicatorSdo extends DomainObject {
Instant getValidFrom();

@JsonProperty("valid_until") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@Redactable
Optional<Instant> getValidUntil();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ public interface IntrusionSetSdo extends DomainObject {
Set<String> getAliases();

@JsonProperty("first_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@Redactable
Optional<Instant> getFirstSeen();

@JsonProperty("last_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@Redactable
Optional<Instant> getLastSeen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ public interface ObservedDataSdo extends DomainObject {

@NotNull
@JsonProperty("first_observed")
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@Redactable(useMask = true)
Instant getFirstObserved();

@NotNull
@JsonProperty("last_observed")
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@Redactable(useMask = true)
Instant getLastObserved();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public interface ReportSdo extends DomainObject {

@NotNull
@JsonProperty("published")
@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@Redactable(useMask = true)
Instant getPublished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
@Redactable
public interface SightingSro extends RelationshipObject {

@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@JsonProperty("first_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@Redactable
Optional<Instant> getFirstSeen();

@JsonSerialize(using = InstantSerializer.class)
@JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC")
@JsonProperty("last_seen") @JsonInclude(value = NON_EMPTY, content= NON_EMPTY)
@Redactable
Expand Down
47 changes: 47 additions & 0 deletions src/test/groovy/stix/end2end/IndicatorSdoSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package stix.end2end

import com.fasterxml.jackson.databind.ObjectMapper
import io.digitalstate.stix.bundle.Bundle
import io.digitalstate.stix.json.StixParsers
import io.digitalstate.stix.sdo.objects.AttackPattern
import io.digitalstate.stix.sdo.objects.Indicator
import io.digitalstate.stix.sdo.objects.IndicatorSdo
import io.digitalstate.stix.sdo.objects.Report
import spock.lang.Shared
import spock.lang.Specification

import java.time.Instant

class IndicatorSdoSpec extends Specification {

@Shared ObjectMapper mapper = new ObjectMapper()

def "Create Indicator SDO and cycle from object to Json back to object"() {

when: "a objects are created,"
IndicatorSdo indicator1 = Indicator.builder()
.addLabels("malicious-activity")
.name("some name")
.validFrom(Instant.now())
.pattern("some pattern")
.build()

then: "Create a Report and Add Attack Patterns as Report Objects"

println indicator1.toJsonString()
String indicator1Json = indicator1.toJsonString()

println StixParsers.parseObject(indicator1Json).inspect()

and: "Create a bundle with the indicator"
Bundle bundle = Bundle.builder()
.addObjects(indicator1)
.build()

println bundle.toJsonString()

println StixParsers.parseBundle(bundle.toJsonString()).inspect()

}

}

0 comments on commit 1704d7f

Please sign in to comment.