Annotation processor that generates ParseObject subclasses from schema objects. Tested on Android. Currently in alpha, USE AT YOUR OWN RISK!!!
AnnotatedParseObject works by processing schemas. Schemas are annotated POJOs that describe the schema of your ParseObject subclasses. Currently two annotations are supported:
@AnnotatedParseObject
: describes the class that will be generated by the processor
@ParseKey
: names the key that represents the column in the Parse database.
Currently in the Parse Android SDK we can't synthesize properties, leading to a frustrating amount of boilerplate:
@ParseClassName("Article")
public class Article extends ParseObject {
private static final String KEY_TITLE = "title";
private static final String KEY_LINK = "link";
private static final String KEY_AUTHOR = "author";
public String getTitle() {
return get(KEY_TITLE);
}
public void setTitle(String title) {
set(KEY_TITLE, title);
}
etc...
}
AnnotatedParseObject can generate this for us:
@AnnotatedParseObject(
parseClassName = "Article",
superClass = ParseObject.class
)
public class ArticleSchema {
public String title;
public String url;
public Author author;
}
Schema objects must follow the format ObjectSchema. So ArticleSchema generates class Article, AuthorSchema generates class Author, etc.
Properties are created by adding get/set to capitalized field name, so title becomes getTitle/setTitle.
The Parse key name (column name in Parse database) is assumed to be the same as the field name (case sensitive).
If this is not the case you can specify it with @ParseKey
:
@AnnotatedParseObject(
parseClassName = "Article",
superClass = ParseObject.class
)
public class ArticleSchema {
public String title;
@ParseKey("link")
public String url;
public Author author;
}
generates:
@ParseClassName("Article")
public class Article extends ParseObject {
public String getUrl() {
return (String)get("link");
}
public void setUrl(String value) {
put("link", value);
}
...
}
Required: apt, Parse Android SDK
In your app module's build.gradle add the following buildscript and apply the plugin:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
Add dependencies:
dependencies {
...
compile 'the.autarch:annotatedparseobject:0.3'
apt 'the.autarch:annotatedparseobject-compiler:0.3'
compile 'com.parse:parse-android:1.13.1'
}