question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@DoNotExpose Annotation

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
NightlyNexuscommented, Feb 20, 2017

Use the transient modifier?

2reactions
arundhajcommented, Jun 22, 2017

@lyubomyr-shaydariv True 😉. For an API project which I’m working on, though I have few fields (around 15-20), I have many classes (around 35-40). For now, I use two duplicate classes; one for domain objects and one for API objects. I use API objects only for external interface and domain objects for everything else used internally. Specific to this issue, I’m using User Defined Exclusion Strategy to annotate few fields to @GsonExclude instead of many fields to @Expose.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gson: @Expose vs @SerializedName - Stack Overflow
suppose if i put i annotation Expose on top of a variable name or password without SerializedName, it will be serialized AS variable...
Read more >
Gson Builder — How to Ignore Fields with @Expose
All following uses of gson will respect the @Expose annotation. @Expose is an easy way to control which values get (de)serialized. We recommend ......
Read more >
Expose (Gson 2.6.2 API) - javadoc.io
The @Expose annotation is useful in a style of programming where you want to explicitly specify all fields that should get considered for...
Read more >
Don't expose your JPA entities in your REST API
Exposing entities in your REST API might look like an easy shortcut but it creates a lot of problems.Here are my main reasons...
Read more >
Exclude Fields from Serialization in Gson - Baeldung
gson.annotations @Expose annotation works the other way around. We can use it to declare which fields to serialize, and ignore the others:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found