Bael 7805 how to fix json io exception failed making field property accessible in gson - #19293
Conversation
| <maven.compiler.source>17</maven.compiler.source> | ||
| <maven.compiler.target>17</maven.compiler.target> | ||
| <maven.compiler.release>17</maven.compiler.release> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
There was a problem hiding this comment.
Similar for these, can we rely on the parent for them?
There was a problem hiding this comment.
Without this setting, the build fails with a 'records are not supported in -source 8' error. Anyway, this fragment is shown in the tutorial. I'd leave it as it is.
There was a problem hiding this comment.
I mean, without the Java 17 setting. Encoding is removed
| } catch (Exception e) { | ||
| log.info("Expected exception caught!"); | ||
| e.printStackTrace(); | ||
| } |
There was a problem hiding this comment.
e.printStackTrace() still counts as using System.out - if you want to log the exception put it as a parameter in the logging call - and the logging level should probably be error
Alternatively just let the main method throw exception so we don't have to handle this at all
| String correctJson = "{" | ||
| + "\"name\":\"Java Conference\"," | ||
| + "\"numberOfParticipants\":500," | ||
| + "\"conferenceStart\":{\"year\":2026,\"month\":8,\"day\":17}" | ||
| + "}"; |
There was a problem hiding this comment.
(optional) since you're using a multiline format you can use of the """ syntax so we can avoid the need to escape the double quotes - if you do this then let's make similar changes for all the other JSON strings throughout the codebase
|
|
||
| @Test | ||
| void whenISOTextFormat_thenJsonSyntaxException() { | ||
|
|
There was a problem hiding this comment.
We have a few of these leading whitespace issues on several methods please remove those blank lines at the start and end of methods
| } else { | ||
| log.info("Mode: [ Module Path ] - Module name: " + moduleName); | ||
| } | ||
| LocalDate excpectedDate = LocalDate.of(2026, 8, 17); |
There was a problem hiding this comment.
This is unused - let's remove it (and the import)
| Gson gson = new Gson(); | ||
| ConferencePojoWithDate result = gson.fromJson(correctJson, ConferencePojoWithDate.class); | ||
|
|
||
| LocalDate excpectedDate = LocalDate.of(2026, 8, 17); |
There was a problem hiding this comment.
| LocalDate excpectedDate = LocalDate.of(2026, 8, 17); | |
| LocalDate expectedDate = LocalDate.of(2026, 8, 17); |
Typo
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
| <modelVersion>4.0.0</modelVersion> |
There was a problem hiding this comment.
The placeholder namespaces are fixed, but the xsi:schemaLocation attribute is still missing compared with the sibling modules
| opens gson.exception to com.google.gson; | ||
|
|
||
| exports gson.exception; | ||
| } No newline at end of file |
There was a problem hiding this comment.
Missing newline at end of file
| import com.google.gson.Gson; | ||
| import com.google.gson.JsonIOException; | ||
|
|
||
| public class ModularGsonUnitTest { |
There was a problem hiding this comment.
| public class ModularGsonUnitTest { | |
| class ModularGsonUnitTest { |
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
|
|
||
| public class ModularGsonWithAdapterUnitTest { |
There was a problem hiding this comment.
| public class ModularGsonWithAdapterUnitTest { | |
| class ModularGsonWithAdapterUnitTest { |
No description provided.