am writing fields of an object out like this:
String jsonStr = Main.gson.toJson(myObject);
UFile tempFile = getTempFile();
FileWriter file = new FileWriter(tempFile);
file.write(jsonStr);
file.close();
This writes out fine to a file.
{“myObject”: [{
"Status": 6,
"name": “test”,
“Type": 2
}]}
but if I change a value in the file like such:
{“myObject”: [{
"Status": 1,
"name": “test”,
“Type": 2
}]}
and then do
FileInputStream f = new FileInputStream(tempFile)
StringBuilder text = new StringBuilder();
Scanner scanner = new Scanner(f, "UTF-8");
while (scanner.hasNextLine())
text.append(scanner.nextLine());
myObject mobj = Main.gson.fromJson(text.toString(), myObject.class);
the status value is null.
if I change it back to 6 it shows the status value as 6 fine when it is read in.
Why does changing a value in the file not allow the value to be read in?