tufekoi tufekoi - 1 year ago 96
Java Question

Gson parsing on android with proguard

I only have a parsing problem with Gson when I use proguard. In debug mode and release mode without proguard, everything work fine.

This is my json string :


These are my POJOs :

public class Database {
private List<Table> tables;

public List<Table> getTables() {
return tables;

public void setTables(List<Table> tables) {
this.tables = tables;

public class Table {
private String name;
private List<Column> columns;

public String getName() {
return name;

public void setName(String name) {
this.name = name;

public List<Column> getColumns() {
return columns;

public void setColumns(List<Column> columns) {
this.columns = columns;

I read the file containing the json string and parse it this way :

public Database getDatabase(Context context) throws IOException {
InputStream stream = context.getAssets().open(PATH);
String schema = getJsonSchema(stream);
Gson gson = new Gson();
return gson.fromJson(schema, Database.class);

But when I try to call the method
from my
object :

for (Table table : database.getTables()) {

I receive this error :
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
. I have included those rules for proguard. Any idea what's the reason ?

Answer Source

As darwin commented, adding the @Keep annotation to my POJOs classes fixed the issue

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download