google / google/gson

@DoNotExpose Annotation

Open
#1,020 6 comments 4 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 was wondering why not include an annotation that allows the exclusion of only a single field or just few fields while serialization.

Example:

`Class Test{
String s1;
String s2;
String s3;
String s4;
}`

If I want to avoid serializing s1 and want to expose the other fields then it currently would look like :

`Class Test{
String s1;
@Expose String s2;
@Expose String s3;
@Expose String s4;
}`

But, I think it would be way more easier to have it the following :

`Class Test{
**@DoNotExpose** String s1;
String s2;
String s3;
String s4;
}`

Can someone please tell if there is a reason for not having this annotation or if there is a cleaner workaround for this available already, as we have a case where we want to avoid serializing a single heavy reference in classes and still expose the other fields.

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.