Skip to content

JSON Parser

Don Peter edited this page Oct 11, 2017 · 2 revisions

JSON Parser

You may specify the fields for conversion using @Json annotation in corresponding getter methods.
Only fields with @Json annotation will be considered for conversion to JSON fields.

You may specify custom field names using @Json(fieldName = "field_name") annotation.

    @Json(fieldName = "field_created_at")
    public long getCreatedAt() {
        return post.getCreatedAt();
    }

This will translate to

{
  "field_created_at":21355
}

You need to specify @JSON annotation for getter methods of corresponding fields.
In case you don't provide a custom Json fieldName, name in lowercase will be used.

    @Json
    public long getCreatedAt() {
        return post.getCreatedAt();
    }

This will translate to

{
  "created_at":21355
}
Clone this wiki locally