google / google/gson

How to use default type value for RuntimeTypeAdapterFactory?

Open
#1,729 1 comment 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

I found this code snippet, which checks existence of field `typeFieldName`:
https://github.com/google/gson/blob/ceae88bd6667f4263bbe02e6b3710b8a683906a2/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java#L222-L236

I wonder if there is any way to set default value for field `typeFieldName` when `deserialization` json string to java object? Or the only way is to override this method (basically copy and paste but provide the default value when there is none):
https://github.com/google/gson/blob/ceae88bd6667f4263bbe02e6b3710b8a683906a2/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java#L207

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.