Este es mi archivo Json:
[{"nombre":"Activo","valor": 8500},{"nombre":"Pasivo","valor":500000}]
Y quiero agregar a la ultima posicion de ese array otro objeto utilizando Gson, yo probe lo siguiente:
public void add(Cuenta cuenta) throws IOException{
String cuentaSerializada = myGson.toJson(cuenta);
this.writeJson(cuentaSerializada);
}
private void writeJson(String cuentaSerialized) throws IOException{
this.bufferToWrite = new BufferedWriter(new FileWriter(this.filePath, true));
this.bufferToWrite.append(cuentaSerialized);
this.bufferToWrite.close();
}
Pero lo unico que hace es agregar un objeto fuera del array:
[{"nombre":"Activo","valor": 8500},{"nombre":"Pasivo","valor":500000}]{"nombre":"Patrimonio","valor":152000}
Utilizo Java en Eclipse