Skip to content

Annotations needed when using Retrofit if attribute names are uppercase #238

Open
@qzo

Description

@qzo

OK, this might not be technically incorrect, but it's confusing at least for me.
Consuming APIs with Retrofit

You can select the Annotation style to Gson, but it's not entirely necessary since the Java file created will work without it.

I've just tried using OMDB API (example:
http://www.omdbapi.com/?i=tt0816692&plot=short&r=json
) and spent some time wondering why most of the values in my object are null, until I realized the problem is most of the attribute names are uppercase, while the variable names are lowercase. With Gson annotations like:

@SerializedName("Title")
@Expose
private String title;

the problem went away.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions