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

Ignore "message" property for deserialization of custom Throwable #4072

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t

// 23-Jan-2018, tatu: One concern would be `message`, but without any-setter or single-String-ctor
// (or explicit constructor). We could just ignore it but for now, let it fail

// [databind#4071]: In case of "message", skip for default constructor
if (PROP_NAME_MESSAGE.equalsIgnoreCase(propName)) {
p.skipChildren();
continue;
}
// Unknown: let's call handler method
handleUnknownProperty(p, ctxt, throwable, propName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.fasterxml.jackson.databind.exc;

import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;

// [databind#4071]: Ignore "message" for custom exceptions with only default constructor
public class CustomExceptionDeser4071Test extends BaseMapTest
{
static class CustomThrowable4071 extends Throwable { }

static class CustomRuntimeException4071 extends RuntimeException { }

static class CustomCheckedException4071 extends Exception { }

private final ObjectMapper MAPPER = newJsonMapper();

public void testCustomException() throws Exception
{
String exStr = MAPPER.writeValueAsString(new CustomThrowable4071());
assertNotNull(MAPPER.readValue(exStr, CustomThrowable4071.class));
}

public void testCustomRuntimeException() throws Exception
{
String exStr = MAPPER.writeValueAsString(new CustomRuntimeException4071());
assertNotNull(MAPPER.readValue(exStr, CustomRuntimeException4071.class));
}

public void testCustomCheckedException() throws Exception
{
String exStr = MAPPER.writeValueAsString(new CustomCheckedException4071());
assertNotNull(MAPPER.readValue(exStr, CustomCheckedException4071.class));
}

public void testDeserAsThrowable() throws Exception
{
_testDeserAsThrowable(MAPPER.writeValueAsString(new CustomRuntimeException4071()));
_testDeserAsThrowable(MAPPER.writeValueAsString(new CustomCheckedException4071()));
_testDeserAsThrowable(MAPPER.writeValueAsString(new CustomThrowable4071()));
}

private void _testDeserAsThrowable(String exStr) throws Exception
{
assertNotNull(MAPPER.readValue(exStr, Throwable.class));
}
}