This is my Json file:
[{"nombre":"Activo","valor": 8500},{"nombre":"Pasivo","valor":500000}]
And I want to add another object to the last position of that array using Gson, I try the following:
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();
}
But the only thing it does is add an object outside the array:
[{"nombre":"Activo","valor": 8500},{"nombre":"Pasivo","valor":500000}]{"nombre":"Patrimonio","valor":152000}
I use Java in Eclipse