google / google/gson

Request: @SerializedName for alternate only

Open
#1,692 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

We're trying to use `@SerializedName` with only `alternate`. I noticed it requires both arguments (`value`-for both directions and `alternate`-for deserialization)

But here's the rub. We use gson for two different use cases in our app. For one, we use the snake_case naming strategy and for the other we use the camelCase strategy. But if we set `@SerializedName(value="someKey", alternate={"alt1", "alt2"})` our snake_case serializer breaks.

So my ask is could we have a way to provide `alternate` without setting `value`?
Maybe a new annotation for alternates?
Or even change the implementation so that when `value == null`, it will fall back to default behavior.

Thoughts?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.