MismatchedInputException: @JsonCreator ignored with ParameterNamesModule and Getter
See original GitHub issueSimilar to #1318 and #1924 but (perhaps significantly?) different reproduction method.
Tested on 2.9.1
and 2.9.6
(currently latest). Works without ParameterNamesModule registered (or if compiled without -parameters
, of course!)
import java.util.UUID;
public class JsonCreatorTest
{
@Test
public void deleteMe() throws Exception
{
new ObjectMapper()
.registerModule(new ParameterNamesModule())
.readValue("\"6994179a-11ff-4fdd-969c-bc977b50332d\"", UuidWrapper.class);
}
public static class UuidWrapper
{
private final UUID val;
public UUID getVal()
{
return val;
}
private UuidWrapper(UUID val)
{
this.val = val;
}
@JsonCreator
public static UuidWrapper valueOf(String val)
{
return new UuidWrapper(UUID.fromString(val));
}
}
}
Causes:
com.fasterxml.jackson.databind.exc.MismatchedInputException:
Cannot construct instance of `foo.JsonCreatorTest$UuidWrapper` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('6994179a-11ff-4fdd-969c-bc977b50332d')
at [Source: (String)""6994179a-11ff-4fdd-969c-bc977b50332d""; line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1031)
at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:371)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:323)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1373)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:171)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004)
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Can't deserialize simplest Object with final field bu Jackson
This can be done by annotating the class with @AllArgsConstructor(onConstructor = @__(@JsonCreator)) . Since the constructor is auto-generated, ...
Read more >Inheritance in Jackson | Baeldung
This tutorial will demonstrate how to handle inclusion of subtype metadata and ignoring properties inherited from superclasses with Jackson.
Read more >FasterXML - Bountysource
@JsonProperty-ies are ignored on @JsonCreator and getters are used instead, and inconsistent behavior with ParameterNamesModule module $ 0. Created 4 years ago ...
Read more >How does the default mode work for @JsonCreator?
detected property (inferred from field, setter and/or getter), ... similarly to the following (ignore for now whether the domain is well represented):.
Read more >invaliddefinitionexception cannot construct instance of java sql blob
MismatchedInputException while parsing json reply into object using fasterxml, ... takes a param name of annotated method and looks for its getters/fields.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@xathien Unfortunately as I said, I don’t think there is an easy fix here. Case of 1-arg constructor or factory has to be resolved by some explicit configuration. I would go with
mode = DELEGATING
, and that definitely should work, regardless of parameter names. If not, I would want to fix that part.Thank you for reporting this, and especially for providing reproduction. I will try to modify it so it can be tested without parameter names module, with mock parameter name provider.