Skip to content

Bael 7805 how to fix json io exception failed making field property accessible in gson - #19293

Open
MBuczkowski2025 wants to merge 14 commits into
eugenp:masterfrom
MBuczkowski2025:BAEL-7805_How_to_fix_JsonIOException_Failed_making_field_property_accessible_in_Gson
Open

Bael 7805 how to fix json io exception failed making field property accessible in gson#19293
MBuczkowski2025 wants to merge 14 commits into
eugenp:masterfrom
MBuczkowski2025:BAEL-7805_How_to_fix_JsonIOException_Failed_making_field_property_accessible_in_Gson

Conversation

@MBuczkowski2025

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread json-modules/gson-4/pom.xml Outdated
Comment thread json-modules/gson-4/pom.xml Outdated
Comment on lines +24 to +27
<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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar for these, can we rely on the parent for them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, without the Java 17 setting. Encoding is removed

Comment thread json-modules/gson-4/gson-module/src/test/java/gson/exception/ModularGsonTest.java Outdated
Comment thread json-modules/gson-4/gson-module/pom.xml Outdated
Comment thread json-modules/gson-4/pom.xml Outdated
Comment on lines +31 to +34
} catch (Exception e) {
log.info("Expected exception caught!");
e.printStackTrace();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +17 to +21
String correctJson = "{"
+ "\"name\":\"Java Conference\","
+ "\"numberOfParticipants\":500,"
+ "\"conferenceStart\":{\"year\":2026,\"month\":8,\"day\":17}"
+ "}";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LocalDate excpectedDate = LocalDate.of(2026, 8, 17);
LocalDate expectedDate = LocalDate.of(2026, 8, 17);

Typo

Comment on lines +1 to +4
<?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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at end of file

import com.google.gson.Gson;
import com.google.gson.JsonIOException;

public class ModularGsonUnitTest {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class ModularGsonUnitTest {
class ModularGsonUnitTest {

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class ModularGsonWithAdapterUnitTest {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class ModularGsonWithAdapterUnitTest {
class ModularGsonWithAdapterUnitTest {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants