Skip to content

Gson

EasyYapi supports Gson annotations for field name mapping and serialization control.

Extension Config

properties
# Gson support (enabled by default when com.google.gson.annotations.SerializedName is on classpath)
field.name=@com.google.gson.annotations.SerializedName#value
field.ignore=!@com.google.gson.annotations.Expose#serialize

Supported Annotations

AnnotationRuleDescription
@SerializedNamefield.nameUse the specified name instead of the field name
@Exposefield.ignoreIgnore fields where serialize=false

Example

java
public class User {
    @SerializedName("user_name")
    private String name;

    @Expose(serialize = false)
    private String password;
}

In this example, name will be documented as user_name, and password will be ignored.

Released under the Apache-2.0 License.