Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

A class has two constructors, and Jackson fails with 'Cannot construct instance of Price (no Creators, like default constructor, exist): cannot deserialize from Number value'. The JSON is just 12.5. Explain and fix.

The JSON 12.5 is a single scalar value, not an object, so Jackson can only build a Price from it with a delegating creator: a constructor or static factory that takes the whole value as one argument. With two constructors, Jackson does not know which one to use or how, so it finds no creator at all. We fix it by marking the one-argument constructor with @JsonCreator(mode = JsonCreator.Mode.DELEGATING), pair it with @JsonValue on the getter so the round trip works, and can set a mapper-wide default for single-argument constructors with ConstructorDetector.

Why this question is asked

Value objects such as Price, Email or OrderId often travel in JSON as plain values: "total": 12.5 rather than "total": {"amount": 12.5}. That is a good design, but it relies on Jackson knowing how to turn a bare number into our class, and the error message when it does not is long and not very clear. Interviewers use this case to see whether we understand Jackson's two kinds of creators. In this answer, we will recap properties and delegating creators, reproduce the failure, explain why two constructors confuse Jackson, fix it with an explicit mode, complete the round trip with @JsonValue, and look at the mapper-wide setting.

1A Quick Recap of Creators

A creator is a constructor or static factory method that Jackson calls to build an object. There are two kinds. A properties creator takes one argument per JSON property: Jackson reads a JSON object, collects the values by name, and passes them in, as in Price(@JsonProperty("amount") BigDecimal amount, @JsonProperty("currency") String currency). A delegating creator takes exactly one argument, and Jackson first deserializes the whole JSON value into that argument's type and then hands it over. A delegating creator is the only way to build an object from a scalar such as 12.5 or "EUR 12.50", because a scalar has no property names to match.

Properties creator compared with delegating creator
Properties creatorDelegating creator
JSON it readsAn object: {"amount": 12.5}Any value: 12.5, "x", [1,2]
ArgumentsOne per property, matched by nameExactly one, the whole value
Typical useDTOs and recordsValue objects written as scalars
Annotation@JsonCreator plus @JsonProperty@JsonCreator(mode = DELEGATING)

2Reproducing the Problem

Here is a Price class with two constructors: one for the amount alone, which uses a default currency, and one for amount and currency. Neither is annotated.

Java
public final class Price {
private final BigDecimal amount;
private final String currency;
public Price(BigDecimal amount) { this(amount, "EUR"); }
public Price(BigDecimal amount, String currency) { this.amount = amount; this.currency = currency; }
public BigDecimal getAmount() { return amount; }
public String getCurrency() { return currency; }
}
mapper.readValue("12.5", Price.class);
// MismatchedInputException: Cannot construct instance of `Price`
// (although at least one Creator exists): no BigDecimal/double-argument
// constructor/factory method to deserialize from Number value (12.5)
// or, depending on version and setup:
// Cannot construct instance of `Price` (no Creators, like default constructor, exist):
// cannot deserialize from Number value (no delegate- or property-based Creator)

The exact text varies between Jackson versions, but the meaning is the same: Jackson found no creator it is willing to use for a number.

3Why Two Constructors Confuse Jackson

Without annotations, Jackson only auto-detects creators in limited cases. It will not pick between several public constructors on its own, because choosing wrong would silently build wrong objects. The two-argument constructor could be a properties creator, but only if Jackson knew its parameter names, and even then it needs a JSON object, not a number. The one-argument constructor could be either a delegating creator or a properties creator with one property called amount. Those two readings expect different JSON, 12.5 versus {"amount": 12.5}, and Jackson cannot tell which one we meant.

So with one-argument constructors Jackson may guess the mode wrongly, or, as here, decline to guess. The cure is to stop relying on detection and state the mode explicitly.

Step throughHow Jackson treats a one-argument constructor
  1. Is it annotated with @JsonCreator?
    YesUse the declared modeNoTry auto-detection
  2. Is the mode declared?DELEGATING or PROPERTIES
    YesFollow it exactlyNoGuess from names and annotations
  3. Guess matches the JSON?Scalar needs DELEGATING
    YesDeserialization worksNoCannot construct instance

3 steps in order. Play them, or step through them one at a time.

Declaring the mode removes the guess.

4The Fix: an Explicit Delegating Creator

We annotate the one-argument constructor, or a static factory, with @JsonCreator(mode = JsonCreator.Mode.DELEGATING). Jackson then deserializes the JSON value as a BigDecimal, the parameter type, and passes it in. The mode is what removes the ambiguity: without it, a one-argument @JsonCreator with a visible parameter name could still be read as a properties creator.

Java
public final class Price {
private final BigDecimal amount;
private final String currency;
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public Price(BigDecimal amount) { this(amount, "EUR"); }
public Price(BigDecimal amount, String currency) { this.amount = amount; this.currency = currency; }
@JsonValue
public BigDecimal getAmount() { return amount; }
public String getCurrency() { return currency; }
}
Price p = mapper.readValue("12.5", Price.class);
System.out.println(p.getAmount() + " " + p.getCurrency()); // 12.5 EUR
System.out.println(mapper.writeValueAsString(p)); // 12.5
record Order(String id, Price total) {}
mapper.readValue("{\"id\":\"o1\",\"total\":12.5}", Order.class); // total = Price 12.5 EUR

A static factory, @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static Price of(BigDecimal amount), works the same way and is often clearer, because it can be named for what it does.

5Completing the Round Trip With @JsonValue

Deserialization is only half of the story. Without @JsonValue, Jackson serializes Price as a bean, {"amount":12.5,"currency":"EUR"}, and our own service could not read its output back as a scalar. @JsonValue on a method tells Jackson to serialize the object as the return value of that method. Paired with a delegating creator, it gives a clean round trip: a Price is written as a number and read from a number.

Notice the design consequence: the scalar form has no room for the currency. If prices can be in several currencies, the scalar form is lossy, and the right JSON is an object with amount and currency, read through a properties creator. Choosing a scalar form is a contract decision, not only a Jackson trick.

6Setting a Default With ConstructorDetector

When a code base has many single-value classes, annotating each one is repetitive. Since Jackson 2.12 the mapper can be given a ConstructorDetector, a policy for how to treat single-argument constructors that are not annotated with a mode. ConstructorDetector.USE_DELEGATING treats them as delegating, USE_PROPERTIES as properties-based, and the default heuristic tries to guess.

Java
ObjectMapper mapper = JsonMapper.builder()
.constructorDetector(ConstructorDetector.USE_DELEGATING)
.build();
// Now a single-argument @JsonCreator without a mode is treated as delegating

I would still prefer explicit modes on the classes themselves for public types, because a mapper setting is invisible when someone reads the class, and a service with a differently configured mapper would behave differently. A shared configuration can set the detector as a safety net.

7Follow-up questions

When is a properties creator the right choice for a one-argument constructor?

When the JSON really is an object with one property, such as {"email": "a@x.com"} for an EmailChange request. Then I write @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) with @JsonProperty("email") on the parameter, so Jackson does not read the whole value into it.

Can a class have both a delegating and a properties creator?

Yes, one of each. Jackson uses the delegating creator for scalar input and the properties creator for object input. That is handy during a migration from {"amount": 12.5} to 12.5 or the other way round, because both forms are accepted for a while.

Does this work with records?

Yes. A record with one component can declare a static factory or an extra constructor with @JsonCreator(mode = DELEGATING), and put @JsonValue on the accessor. Without that, Jackson uses the canonical constructor as a properties creator and expects an object.

8Conclusion

In this answer, we saw that a scalar value such as 12.5 can only be deserialized through a delegating creator, which takes the whole value as one argument. With two unannotated constructors Jackson found no usable creator, so we marked the one-argument constructor with @JsonCreator(mode = DELEGATING), paired it with @JsonValue on the getter for the round trip, and saw that ConstructorDetector can set a mapper-wide default for single-argument constructors.

What to say in the interviewAbout 90 seconds aloud

Open with

The JSON is a bare number, 12.5, not an object, so there are no property names to match. The only way Jackson can build a Price from it is a delegating creator: a constructor or static factory with exactly one argument, where Jackson first reads the whole value as that argument's type, here a BigDecimal, and passes it in.

Then, if they want more

The class has two constructors and neither is annotated, so Jackson does not choose one. The one-argument constructor is ambiguous anyway: it could be a delegating creator or a properties creator for a single property called amount, and those expect different JSON.

So the fix is to say it explicitly: JsonCreator with mode DELEGATING on the one-argument constructor, or on a static factory such as Price.of. Setting the mode is the important part, because a one-argument creator without a mode can still be guessed wrongly.

For the round trip I put JsonValue on getAmount, so Price is also written as 12.5 rather than as an object. I would point out that the scalar form loses the currency, so it only fits if there is one currency.

And if a code base has many such classes, the mapper's ConstructorDetector, for example USE_DELEGATING, sets the default for single-argument constructors, though I prefer explicit modes on public types.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A class has two constructors, and Jackson fails with 'Cannot construct instance of Price...": https://scrivio-interview-library.netlify.app/spring-boot/json-serialization/22cf9044d7/