Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
michaelcdillon opened this issue Jan 13, 2020 · 6 comments
Closed

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

michaelcdillon opened this issue Jan 13, 2020 · 6 comments
Labels
3.0 Issue planned for initial 3.0 release
Milestone

Comments

@michaelcdillon
Copy link

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)
@cowtowncoder
Copy link
Member

cowtowncoder commented Jan 22, 2020

Unfortunately this can not be supported before adding support for JDK9 or later (in practice JDK11 as that is the first LTS unlike JTK9) -- constructor to pass these properties was added in JDK9 so is not available before.

I think this would need something like Java11DatatypeModule (or just Java11Module).
I think I will create a new tag for this, in case I (or someone else) has time and needs this feature.

@cowtowncoder cowtowncoder added 3.x Issues to be only tackled for Jackson 3.x, not 2.x JDK11 Features that need JDK11 (and/or support JDK11) labels Jan 22, 2020
@michaelcdillon
Copy link
Author

Okay thanks for looking into this, I really appreciate it. Any chance you have a suggestion on a quick and dirty work around?

@cowtowncoder
Copy link
Member

@michaelcdillon Hmmh. Could perhaps either copy-paste existing StackTraceElementDeserializer, or just write and register custom-written one?

@michaelcdillon
Copy link
Author

Sounds good, thanks. Also thanks for the effort you put in here!

@cowtowncoder
Copy link
Member

@michaelcdillon no problem!

Also: creating a new module for JDK9 (or JDK11 depending), assuming there might be other types that need support, is not tons of work. Just in case you or anyone else finding this wanted to see where that could lead. Other users could find it useful and we could add it as one of FasterXML modules.

@cowtowncoder cowtowncoder added 3.0 Issue planned for initial 3.0 release and removed 3.x Issues to be only tackled for Jackson 3.x, not 2.x JDK11 Features that need JDK11 (and/or support JDK11) labels Dec 1, 2024
@cowtowncoder cowtowncoder added this to the 3.0.0 milestone Dec 12, 2024
@cowtowncoder
Copy link
Member

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 Issue planned for initial 3.0 release
Projects
None yet
Development

No branches or pull requests

2 participants