When I'm running this code the file is created, but it is empty although output looks OK
import java.io.IOException;
public class JasonTest {
public static void main(String[] args) throws IOException {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
TestJson tj = new TestJson(13, "kuku");
gson.toJson(tj, new FileWriter("test.json"));
System.out.println(gson.toJson(tj));
}
}
Output:
{
"num": 13,
"text": "kuku"
}
Process finished with exit code 0