Skip to content

Conversation

jasperblues
Copy link

We require the ability to exclude null fields, therefore

Similar to the Jackson serializer for Java, add support for a global include policy: https://fasterxml.github.io/jackson-annotations/javadoc/2.7/com/fasterxml/jackson/annotation/JsonInclude.Include.html

Current possible values are: [DEFAULT, NON_NULL]

  • Default includes all defined fields.
  • NON_NULL omits null fields.

Copy link
Member

@saulotoledo saulotoledo left a comment

Choose a reason for hiding this comment

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

Hi @jasperblues, thanks for your contribution.
Are you still interested in this change?

I am not sure if this will be accepted, but I believe it might be useful to discuss it with the current maintainer. In the meanwhile I did a first review in your code. If you are still interested on it, please submit an updated version of your PR. If accepted, additional changes may be required before the final approval.

In addition, you will need to rebase your branch with the current development branch.

"remap-istanbul": "^0.7.0",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"ts-node": "^8.3.0",
Copy link
Member

Choose a reason for hiding this comment

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

This file and the package-lock.json are not required and should be removed from this PR.

*/
includePolicy?: Include;


Copy link
Member

Choose a reason for hiding this comment

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

Please remove the double spaces.

@@ -0,0 +1,10 @@
export enum Include {
Copy link
Member

Choose a reason for hiding this comment

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

We should discuss the name for this enum. This one is not clear enough.

return keys.filter((it: string) => object[it] !== null);
} else {
throw new Error(`Unsupported Include policy ${include}`);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested changes:

if (include === Include.DEFAULT) {
    return keys;
}

if (include === Include.NON_NULL) {
    return keys.filter((it: string) => object[it] !== null);
}

throw new Error(`Unsupported Include policy ${include}`);

The variable names include and it are not clear enough. Please consider changing them later.


class User {


Copy link
Member

Choose a reason for hiding this comment

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

Please remove double spaces.

@jasperblues
Copy link
Author

Are you still interested in this change?

I'm no longer personally interested, but happy to update if it looks useful for community.

@NoNameProvided NoNameProvided added the status: blocked Issues being blocked by a different issue. label Aug 7, 2020
laurence-myers pushed a commit to laurence-myers/class-transformer that referenced this pull request Apr 23, 2021
…per Blues for the "include policy", and feedback from the pull request.

typestack#284
laurence-myers pushed a commit to laurence-myers/class-transformer that referenced this pull request Apr 23, 2021
…per Blues for the "include policy", and feedback from the pull request.

typestack#284
laurence-myers pushed a commit to laurence-myers/class-transformer that referenced this pull request Apr 23, 2021
…ies if they have null values. Re-implements pull request typestack#284, incorporating changes by Jasper Blues for the "include policy", and feedback from the pull request.

typestack#284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked Issues being blocked by a different issue.
Development

Successfully merging this pull request may close these issues.

4 participants