Skip to content

Omit array-based keys that are empty for assets - #694

Merged
seansica merged 3 commits into
mainfrom
fix-assets-serialization
Oct 22, 2025
Merged

seansica merged 3 commits into
mainfrom
fix-assets-serialization

Conversation

@seansica

Copy link
Copy Markdown
Contributor

Addresses mitre-attack/attack-workbench-rest-api#430 for fields explicitly managed by assets

Complementary change for backend PR mitre-attack/attack-workbench-rest-api#431

This change ensures that array-based fields explicitly managed by the Asset SDO stop defaulting to empty lists when they are serialized during POST and PUT operations. Instead, array-based fields will be omitted.

- Adds a new method, serializeArrayField, to parent class, StixObject
- The method conditionally serializes an array field to the target object only if it contains at least one element
- Modifies Asset SDO to ensure that empty arrays are never included in the serialized STIX object sent to backend
- Only effects fields explicitly handled by the Asset SDO, not common fields inherited from StixObject

Tested E2E workflow and confirmed the POSTed request body no longer contain empty arrays
Comment thread src/app/classes/stix/stix-object.ts Outdated
protected serializeArrayField(
target: any,
key: string,
value: any[],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use generics instead of any, just so we can make sure the types match?

protected serializeArrayField<T>(target: any, key: string, value: T[], transform? (val: T[]) => T)

@seansica
seansica merged commit fefd3d4 into main Oct 22, 2025
2 checks passed
@seansica
seansica deleted the fix-assets-serialization branch October 22, 2025 20:00
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.6.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

seansica added a commit that referenced this pull request Mar 19, 2026
…ssets-serialization

Omit array-based keys that are empty for assets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants