-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Deprecate ObjectMapper.canDeserialize()
/ObjectMapper.canSerialize()
in 2.18
#4570
Comments
Along with deprecating the two methods, shall we come up with alternative way to achieve the same functionality which may be added to deprecated methos' javadocs so users know what to do later on? |
@JooHyukKim There isn't really matching functionality, unfortunately: there is no good way (that I know of) to figure it in useful manner whether something is reliably (de)serializable; from what kind of input and so on. Calling applications should not -- for example -- try to obtain serializer or deserializer. I am +1 on improvements to Javadocs, just not sure what to say other than "these seemed like a good idea but weren't". |
@cowtowncoder I think the Javadoc or the deprecation should mention what you said in the comment. As it stands, the "use discouraged" is unhelpful IMO. And if possible, provide an alternative solution. My use case for it is for testing that my module setup correctly: class ExampleApiJacksonModuleTests {
private ObjectMapper objectMapper;
@BeforeEach
void setUp() {
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new ExampleApiJacksonModule());
}
@Test
void registersDeserializers() {
assertThat(objectMapper.canDeserialize(
objectMapper.constructType(new TypeReference<ExampleRequest>() {})))
.isTrue();
assertThat(objectMapper.canDeserialize(
objectMapper.constructType(new TypeReference<ExampleResponse>() {})))
.isTrue();
assertThat(objectMapper.canDeserialize(objectMapper.constructType(new TypeReference<IntentRegistry>() {})))
.isTrue();
}
@Test
void registersSerializers() {
assertThat(objectMapper.canSerialize(ExampleRequest.class)).isTrue();
assertThat(objectMapper.canSerialize(ExampleResponse.class)).isTrue();
}
} Note I have other tests that test against JSON and that may be the only solution to the above -- test serialization/deserialization against live/real JSON. |
@ciscoo in your case, you really should just verify serialization/deserialization works correctly. I hope @JooHyukKim 's javadoc improvements help. |
…ObjectMapper.canSerialize()` deprecation (#4826)
@cowtowncoder Yes, I have tests for that today using raw/real JSON which works fine. The added javadoc from @JooHyukKim is indeed helpful. For those that want more of the why or nitty-gritty details can look at the git blame and refer back to this issue which is how I landed here originally. |
It is too bad because intuitively these methods have simple straight-forward names and seemingly simple semantics. It is unfortunate they really cannot be well implemented, with pluggable (de)serializers, various failure modes etc. This just as background for deprecation. |
(note: offshoot of discussion in #4568)
As per #1917 there is limited value in these 2 methods (and underlying machinery), and hence they are dropped from 3.0, as we cannot drop them from 2.x due to backwards-compatibility requirements.
But since the fundamental problem exists, we should mark them as
@deprecated
in 2.x (specifically, 2.18).The text was updated successfully, but these errors were encountered: