Skip to content

StackTraceElement w/ >= Java 9 doesn't deserialize properly #2593

@michaelcdillon

Description

@michaelcdillon

Using ObjectMapper to serialize and then deserialize a StackTraceElement results in an instance with null values for classLoaderName, moduleName, and moduleVersion. Those elements are present in the serialized form, but then do not make it into the instance supplied by
readValue("...", StackTraceElement.class).

Versions:

  • Java: >= 9, using 11.0.4
  • Jackson-Databind: 2.10.2

Example Test Case:

@Test
public void testStackTraceElementIsSerializableAfterJava9() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    StackTraceElement element = new StackTraceElement(
        "testClassloader",
        "testModule",
        "module-version",
        "com.test.DeclaringClass",
        "firstMethod",
        "/some/file",
        35
    );
    String serializedElement = mapper.writeValueAsString(element);
    System.out.println("Serialized Element: " + serializedElement);
    assertEquals(element, mapper.readValue(serializedElement, StackTraceElement.class));
}

Serialize Element Print Statement:

{
"classLoaderName": "testClassloader",
"moduleName": "testModule",
"moduleVersion": "module-version",
"methodName": "firstMethod",
"fileName": "/some/file",
"lineNumber": 35,
"className": "com.test.DeclaringClass",
"nativeMethod": false
}

Assertion Failure Output:

Expected: testClassloader/testModule@moduleversion/com.test.DeclaringClass.firstMethod(/some/file:35)
Actual :com.test.DeclaringClass.firstMethod(/some/file:35)

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0Issue planned for initial 3.0 release

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions