Skip to content

Commit

Permalink
revert annotation changes, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoten committed Apr 8, 2024
1 parent d15c9bd commit 1426158
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

/**
* Name to use for serializing value of the attribute; if not defined,
* {@link #creatorType} will be used instead.
* {@link #value} will be used instead.
*/
public String propName() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Annotation that can be used to indicate a {@link PropertyNamingStrategy}
* to use for annotated class. Overrides the global (default) strategy.
* Note that if the {@link #creatorType} property is omitted, its default value
* Note that if the {@link #value} property is omitted, its default value
* means "use default naming" (that is, no alternate naming method is used).
* This can be used as an override with mix-ins.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import java.math.BigDecimal;
import java.math.BigInteger;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;

// [databind#2978]
public class StdValueInstantiatorTest
Expand Down Expand Up @@ -173,4 +175,36 @@ static class B2 {
this.creatorType = 4;
}
}

@Test
public void testJsonIntegerIntoDoubleConstructorThrows() throws JsonMappingException, JsonProcessingException {
ObjectMapper m = new ObjectMapper();
try {
m.readValue("5", D.class);
Assert.fail();
} catch (ValueInstantiationException e) {
assertTrue(e.getCause() instanceof IllegalArgumentException);
assertEquals("boo", e.getCause().getMessage());
}
}

static final class D {

D(double value) {
throw new IllegalArgumentException("boo");
}
}

@Test
public void testJsonLongIntoDoubleConstructorThrows() throws JsonMappingException, JsonProcessingException {
ObjectMapper m = new ObjectMapper();
try {
m.readValue(String.valueOf(LONG_TEST_VALUE), D.class);
Assert.fail();
} catch (ValueInstantiationException e) {
assertTrue(e.getCause() instanceof IllegalArgumentException);
assertEquals("boo", e.getCause().getMessage());
}
}

}

0 comments on commit 1426158

Please sign in to comment.