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

Values that are not set in Java builders should be treated as unset in JavaScript #375

Closed
eladb opened this issue Mar 12, 2019 · 0 comments · Fixed by #376
Closed

Values that are not set in Java builders should be treated as unset in JavaScript #375

eladb opened this issue Mar 12, 2019 · 0 comments · Fixed by #376
Labels
bug This issue is a bug.

Comments

@eladb
Copy link
Contributor

eladb commented Mar 12, 2019

See aws/aws-cdk#965

@eladb eladb added the bug This issue is a bug. label Mar 12, 2019
eladb pushed a commit that referenced this issue Mar 12, 2019
Implement a serialization method for Java POJOs (produced by
calling `build()` on the generated builders such that they
are passed by-value to JavaScript instead of by-reference.

Also, erase any nulls passed in objects to JS, so they are
treated as unset values for the purpose of `key in obj`.
This fixes aws/aws-cdk#965 and fixes #375.
eladb pushed a commit that referenced this issue Mar 12, 2019
Implement a serialization method for Java POJOs (produced by
calling `build()` on the generated builders such that they
are passed by-value to JavaScript instead of by-reference.

Also, erase any nulls passed in objects to JS, so they are
treated as unset values for the purpose of `key in obj`.
This fixes aws/aws-cdk#965 and fixes #375.
eladb pushed a commit that referenced this issue Mar 20, 2019
Data types ("structs") are defined through a TypeScript interface that only contains properties and doesn't begin with an `I`. This change also adds a requirement that all properties (shallow) are marked `readonly`.

This allows passing around structs by-value safely because any consuming code would not expect to be able to write to the object.

Python already passes structs by value, especially in the context of when a struct is used as keyword arguments. This use case will also exist in Ruby.

This is also the general perception around data that's passed around in most programming languages.

To enforce this, the jsii compiler will now fail if a struct includes properties that are not marked `readonly`.

Both the Java and .NET generators have been modified to generate builders which allow users to construct structs by serializing them as JSON hashes instead of passed down by reference.

Existing compliance tests in all languages have been fixed.

This change fixes aws/aws-cdk#965 and fixes #375 by erasing any `null`s or `undefined` values from passed in objects, so they do not appear to have been defined at all. Added a compliance test called **erase-unset-data-values** to verify.

BREAKING CHANGE: all properties in interfaces which represent data types must be marked as `readonly`. Otherwise, jsii compilation will fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant