I'm assuming the malformed date string is a typo as the library is not going to produce that output. I note that you are writing code points with values beyond U+007F.
FileWriter fileWriter = new FileWriter(file);
The above line is defective on any system that does not use a Unicode Transformation Format (UTF) as its default encoding. The documentation states:
The constructors of this class assume that the default character encoding
The same issue is present in FileReader
. Both types should be avoided.
JSON mandates Unicode:
JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.
If you need to provide character data directly to the JSON API you are using, then you must specify the encoding.
Reading:
try (InputStream in = new FileInputStream(filename);
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) {
// read from stream
}
Writing:
try (OutputStream out = new FileOutputStream(filename);
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
// write to stream
}
This is Java 7 code, but the same principles apply in earlier versions. See here for a rough guide to character encoding in Java. The reading mechanism is incomplete as it does not detect which UTF is being used - refer to the spec for the necessary byte-pattern detection.
As a commenter noted, it is insufficient to say "it's not working!" - you must detail the nature of the failure. Java developers expect an error stack trace.