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

More convenient way to specify an annotation value with only one field #1035

Open
niveathika opened this issue Feb 4, 2022 · 1 comment
Open
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design

Comments

@niveathika
Copy link

Description:
Currently, the annotation should be a subtype of one of the three types: true, mapvalue:Cloneable, mapvalue:Cloneanble[].

When annotations are used for mapping record fields such as JSON to/from record conversion and database query results mapping, the annotation needs to contain only one value. Here, repeating the key for the value is a bit cumbersome since there will be numerous fields.

type Person record {
    int id;
    @sql:Column { name = "first_name" }
    string firstName;
    @sql:Column { name = "last_name" }
    string lastName
};

Here, the name key needs to be repeated again and again. With support for string type, this can be simplified as follows:

type Person record {
    int id;
    @sql:Column { "first_name" }
    string firstName;
    @sql:Column { "last_name" }
    string lastName
};
@jclark jclark changed the title Support for string annotation type Allow value of annotation to be a string rather than a record Feb 12, 2022
@jclark jclark changed the title Allow value of annotation to be a string rather than a record More convenient way to specify an annotation value with only one field Feb 12, 2022
@jclark
Copy link
Collaborator

jclark commented Feb 12, 2022

Two ways to approach this:

  1. The value of an annotation is a string rather than a record. (In this case, there would be no curly braces: just @sql:Column "firstName")
  2. The field name can be defaulted (problem is that this conflicts with { x } meaning { x: x }

@anupama-pathirage anupama-pathirage added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

3 participants