Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to convert class to JSON using GSON

When i’m trying to convert an object in my Android App to a Json i get the following error:

class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations

The issue is that in some devices all is working GSON version:

implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

While the code i’m trying to convert the object is the following:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Comanda comanda = new Comanda(
                    tasto.getDescriptionReceipt(),
                    quantitaSelezionata,
                    tasto.getCodice(),
                    turnoValue,
                    currentTimeString,
                    operatore,
                    "A",
                    String.valueOf(tasto.getPrice()));
            intent.putExtra("prodotto", new Gson().toJson(comanda));

Comanda class looks like this:

public class Comanda {

    private final String descProdotto;
    private double qta;
    private int turno;
    private String codice;
    private String time;
    private String codOP;
    private String state;
    private String pre;
    private ArrayList<Varianti> variants = new ArrayList<>();


    public Comanda(String button, double qta, String codice, int turno, String time, String codOP, String state, String pre) {
        this.descProdotto = button;
        this.qta = qta;
        this.codice = codice;
        this.turno = turno;
        this.time = time;
        this.codOP = codOP;
        this.state = state;
        this.pre = pre;
    }

}

public class Varianti implements Serializable {

    String name;
    private String codice;
    BitmapDrawable drawable;
    private String state;
    public String pre;
    public String qta;

    public Varianti(String name, String codice, BitmapDrawable drawable, String state, String pre, String qta) {
        this.name = name;
        this.codice = codice;
        this.drawable = drawable;
        this.state = state;
        this.pre = pre;
        this.qta = qta;
    }
}

Any solution even in kotlin is welcome

>Solution :

I think the problem is the Varianti bean, which has a property
BitmapDrawable . when you use the Gson to convert it to string, you should not handle it.

ublic class Varianti implements Serializable {

    String name;
    private String codice;
    private transient BitmapDrawable drawable;
    private String state;
    public String pre;
    public String qta;

    public Varianti(String name, String codice, BitmapDrawable drawable, String state, String pre, String qta) {
        this.name = name;
        this.codice = codice;
        this.drawable = drawable;
        this.state = state;
        this.pre = pre;
        this.qta = qta;
    }
}


Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading