Reputation: 39539
Is there a simple way to ignore a field when using moshi to serialize to a json string? I can only think about is a custom adapter - but I have the feeling that there is a better way
Upvotes: 13
Views: 10293
Reputation: 3707
According to Moshi's readme:
By default, all fields are emitted when encoding JSON, and all fields are accepted when decoding JSON. Prevent a field from being included by annotating them with
@Json(ignore = true)
.
Upvotes: 0
Reputation: 25310
Use transient
on the field declaration.
private transient String your_variable_name;
Originally I found Exclude fields from serialization and deserialization
Hope It's help you.
Upvotes: 16