Skip to content

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