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

Support of private fields in Resource #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

frecco75
Copy link

@frecco75 frecco75 commented Apr 15, 2019

Today, when we build a Model we need to have public fields because the generated ModelHelper references fields directly.

I have changed the behavior to allow developer to use private fields if any setter exists, which is more standard according to the JavaBeans specification.

Example :

@ContentType("cat")
public class MyModel extends Resource {
  @Field public String publicField;
  @Field private String privateField;
  @Field private String privateFluentField;
 
  //Standard setter
  public void setPrivateField(String privateField) {
    this.privateField = privateField;
  }
 
  //Fluent setter
  public void privateFluentField(String privateFluentField) {
    this.privateFluentField = privateFluentField;
  }
}

will produce a ModelHelper containing

public MyModel fromCursor(Cursor cursor) {
    MyModel result = new MyModel();
    setContentType(result, "cid");
    result.publicField = cursor.getString(3);
    result.setPrivateField(cursor.getString(4));
    result.privateFluentField(cursor.getString(5));
    return result;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant