title: Jackson prefers private constructor over @JsonCreator when deserializing a class with @JsonValue
body: <p>I have a simple class with a private constructor and a static factory.  I want the class to serialize as a number, so I've annotated the getter for the field with <code>@JsonValue</code>.  However, Jackson appears to prefer the private constructor over the static factory, even when I annotate the static factory with <code>@JsonCreator</code>.  It works if I annotate the private constructor with <code>@JsonIgnore</code>, but that feels a bit off.</p>
  
  <p>I've seen some posts claiming that <code>@JsonCreator</code> only works if the parameters are annotated with <code>@JsonProperty</code>; however, that seems to be the case for objects serialized as JSON objects.  This object is being serialized as a number, and thus there is no property to supply to the annotation.</p>
  
  <p>Is there something I'm missing?</p>
  
  <p><em>example class</em>:</p>
  
  <pre><code>package com.example;
  
  import com.fasterxml.jackson.annotation.JsonCreator;
  import com.fasterxml.jackson.annotation.JsonValue;
  import com.google.common.base.Preconditions;
  
  public class NonNegative {
    private final double n;
  
    private NonNegative(double n) {
      this.n = n;
    }
  
    @JsonCreator
    public static NonNegative checked(double n) {
      Preconditions.checkArgument(n &gt;= 0.0);
      return new NonNegative(n);
    }
  
    @JsonValue
    public double getValue() {
      return n;
    }
  
    @Override
    public int hashCode() {
      return Objects.hash(n);
    }
  
    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (obj instanceof NonNegative) {
        NonNegative that = (NonNegative) obj;
        return Objects.equals(n, that.n);
      }
      return false;
    }
  }
  </code></pre>
  
  <p><em>example tests:</em></p>
  
  <pre><code>package com.example;
  
  import static org.assertj.core.api.Assertions.assertThat;
  
  import org.junit.Test;
  
  import com.fasterxml.jackson.databind.JsonMappingException;
  import com.fasterxml.jackson.databind.ObjectMapper;
  
  public class NonNegativeTest {
    private static final ObjectMapper MAPPER = new ObjectMapper();
  
    @Test
    public void itSerializesAndDeserializes() throws Exception {
      NonNegative nonNegative = NonNegative.checked(0.5);
  
      assertThat(MAPPER.readValue(MAPPER.writeValueAsString(nonNegative), NonNegative.class)).isEqualTo(nonNegative);
    }
  
    /* This test fails. */
    @Test(expected = JsonMappingException.class)
    public void itDoesNotDeserializeANegativeNumber() throws Exception {
      MAPPER.readValue(MAPPER.writeValueAsString(-0.5), NonNegative.class);
    }
  }
  </code></pre>