class A declares multiple JSON fields

Since they are private fields there should not be any problem while creating json string

I don’t think this statement is true, GSON looks up at the object’s private fields when serializing, meaning all private fields of superclass are included, and when you have fields with same name it throws an error.

If there’s any particular field you don’t want to include you have to mark it with transient keyword, eg:

private transient BigDecimal tradeFeesPcy;

Leave a Comment