-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix #4688 2.18.0-rc1 Regression deserializing with no-arg delegating JsonCreator #4689
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.fasterxml.jackson.databind.deser.creators; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
||
// [databind#4688] | ||
public class SingletonDelegatingCreatorTest extends DatabindTestUtil | ||
{ | ||
static final class NoFieldSingletonWithDelegatingCreator { | ||
static final NoFieldSingletonWithDelegatingCreator INSTANCE = new NoFieldSingletonWithDelegatingCreator(); | ||
|
||
private NoFieldSingletonWithDelegatingCreator() {} | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so would the idea here be to basically drop any JSON value that would match this type? This was not something intended to work, although if it did use to work there's something to be said for not changing behavior. Will add a note on issue itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, our intent was to explicitly match an empty json object on the server-side (where we fail-on-unknown-fields) and allow clients which do not set that property to be api-compatible with future additions to the type. |
||
static NoFieldSingletonWithDelegatingCreator of() { | ||
return INSTANCE; | ||
} | ||
} | ||
|
||
static final class NoFieldSingletonWithPropertiesCreator { | ||
static final NoFieldSingletonWithPropertiesCreator INSTANCE = new NoFieldSingletonWithPropertiesCreator(); | ||
|
||
private NoFieldSingletonWithPropertiesCreator() {} | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
static NoFieldSingletonWithPropertiesCreator of() { | ||
return INSTANCE; | ||
} | ||
} | ||
|
||
static final class NoFieldSingletonWithDefaultCreator { | ||
static final NoFieldSingletonWithDefaultCreator INSTANCE = new NoFieldSingletonWithDefaultCreator(); | ||
|
||
private NoFieldSingletonWithDefaultCreator() {} | ||
|
||
@JsonCreator | ||
static NoFieldSingletonWithDefaultCreator of() { | ||
return INSTANCE; | ||
} | ||
} | ||
|
||
/* | ||
/********************************************************************** | ||
/* Test methods | ||
/********************************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
@Test | ||
public void testNoFieldSingletonWithDelegatingCreator() throws Exception | ||
{ | ||
NoFieldSingletonWithDelegatingCreator deserialized = MAPPER.readValue("{}", | ||
NoFieldSingletonWithDelegatingCreator.class); | ||
assertSame(NoFieldSingletonWithDelegatingCreator.INSTANCE, deserialized); | ||
} | ||
|
||
@Test | ||
public void testNoFieldSingletonWithPropertiesCreator() throws Exception | ||
{ | ||
NoFieldSingletonWithPropertiesCreator deserialized = MAPPER.readValue("{}", | ||
NoFieldSingletonWithPropertiesCreator.class); | ||
assertSame(NoFieldSingletonWithPropertiesCreator.INSTANCE, deserialized); | ||
} | ||
|
||
@Test | ||
public void testNoFieldSingletonWithDefaultCreator() throws Exception | ||
{ | ||
NoFieldSingletonWithDefaultCreator deserialized = MAPPER.readValue("{}", | ||
NoFieldSingletonWithDefaultCreator.class); | ||
assertSame(NoFieldSingletonWithDefaultCreator.INSTANCE, deserialized); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not entirely clear if we should use a property creator with no properties, or
creators.setDefaultCreator(candidate.creator());
. The former seems more explicit, but the latter more closely matches the previous implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your choice; let's go with that (possible to change, too, if need arises).