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

Serialiser_Engine: Improve size of JSON by excluding empty IBHoMObject properties #3144

Merged
merged 5 commits into from
Aug 16, 2023

Conversation

FraserGreenroyd
Copy link
Contributor

@FraserGreenroyd FraserGreenroyd commented Aug 14, 2023

Fixes #3017

Test file available here.

Test file is very simple - serialise any object implementing IBHoMObject (should be most - I went with an Environment oM Panel) without providing a Name or other property implemented from IBHoMObject - see that the JSON doesn't contain the key value pair for those properties. Then provide values to those properties and see them get included.

I opted to go with storing the property names on load so that if you're serialising a collection of IBHoMObjects, we don't lose time querying the same 5 property names over and over again. Also opted to query the IBHoMObject properties so that if we ever change them, we don't have to remember to update the list here.

I did consider the option of whether we would want to include empty properties if they were overridden (as @IsakNaslundBh has occasionally done to override the Name property so he can add his own description to it for certain Structural objects), but decided against it for now on the basis that this will only exclude them if they're empty - so even if they're overridden, if they have no value assigned, do we really want them taking up space in the JSON string? I'm arguing for not - but we could go the other way if there's strong argument to.

@FraserGreenroyd FraserGreenroyd added the type:feature New capability or enhancement label Aug 14, 2023
@FraserGreenroyd FraserGreenroyd self-assigned this Aug 14, 2023
Copy link
Member

@adecler adecler left a comment

Choose a reason for hiding this comment

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

The code doesn't cover the case for the IEnumerable properties (i.e. Tags, Fragments, And CustomData) as they will show in json even if empty:

image

In this case, I wonder if it wouldn't be simpler to use a switch-case on prop.Name to explicitly list the properties to treat differently (simpler and more transparent) ?

@FraserGreenroyd
Copy link
Contributor Author

image

🤦‍♂️ much cleaner! Have implemented the switch - though this does mean we'll need to keep it updated if we ever change the IBHoMObject properties - but given we haven't done that in years, I think that's a minimal overhead compared to the greater transparency this gives.

Copy link
Member

@adecler adecler left a comment

Choose a reason for hiding this comment

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

Now works as expected.
Happy with the state of the code.

@FraserGreenroyd
Copy link
Contributor Author

@BHoMBot check compliance
@BHoMBot check required

@bhombot-ci
Copy link

bhombot-ci bot commented Aug 16, 2023

@FraserGreenroyd to confirm, the following actions are now queued:

  • check code-compliance
  • check documentation-compliance
  • check project-compliance
  • check branch-compliance
  • check dataset-compliance
  • check copyright-compliance
  • check code-compliance
  • check documentation-compliance
  • check project-compliance
  • check core
  • check null-handling
  • check serialisation
  • check versioning
  • check installer

There are 2 requests in the queue ahead of you.

@bhombot-ci
Copy link

bhombot-ci bot commented Aug 16, 2023

The check code-compliance has already been run previously and recorded as a successful check. This check has not been run again at this time.

@bhombot-ci
Copy link

bhombot-ci bot commented Aug 16, 2023

The check documentation-compliance has already been run previously and recorded as a successful check. This check has not been run again at this time.

@FraserGreenroyd
Copy link
Contributor Author

@BHoMBot check installer

@bhombot-ci
Copy link

bhombot-ci bot commented Aug 16, 2023

@FraserGreenroyd to confirm, the following actions are now queued:

  • check installer

@FraserGreenroyd
Copy link
Contributor Author

@BHoMBot this is a DevOps instruction. I am requesting neutral checks on: versioning, unit-tests, installer, ready-to-merge

@bhombot-ci
Copy link

bhombot-ci bot commented Aug 16, 2023

@FraserGreenroyd I have provided neutral checks to the checks requested. These checks will need to be run properly to obtain full results.

@FraserGreenroyd FraserGreenroyd merged commit 952a2dd into develop Aug 16, 2023
13 checks passed
@FraserGreenroyd FraserGreenroyd deleted the Serialiser_Engine-#3017-JSONSize branch August 16, 2023 15:09
@bhombot-ci bhombot-ci bot mentioned this pull request Sep 11, 2023
@bhombot-ci bhombot-ci bot mentioned this pull request Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New capability or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serialiser_Engine: Improve the size of the Json string by ignoring empty values for IBHoMObject properties
2 participants