Skip to content

Commit

Permalink
Fix #2513
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 20, 2019
1 parent 0a47e54 commit c7ff8f6
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project: jackson-databind
(reported by Ryan B)
#2485: Add `uses` for `Module` in module-info
(contributed by Marc M)
#2513: BigDecimalAsStringSerializer in NumberSerializer throws IllegalStateException in 2.10
(reported by Johan H)

2.10.0 (26-Sep-2019)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ public BigDecimalAsStringSerializer() {

@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return valueToString(value).isEmpty();
// As per [databind#2513], should not delegate; also, never empty (numbers do
// have "default value" to filter by, just not "empty"
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected ObjectMapper sharedMapper() {
}
return SHARED_MAPPER;
}

protected ObjectMapper objectMapper() {
return sharedMapper();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static class TestPOJO
/**********************************************************
*/

final ObjectMapper MAPPER = objectMapper();
final ObjectMapper MAPPER = sharedMapper();

public void testSimplePerCall() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static class TestPOJO
/**********************************************************
*/

final ObjectMapper MAPPER = objectMapper();
final ObjectMapper MAPPER = sharedMapper();

public void testSimplePerCall() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class NumericConversionTest extends BaseMapTest
{
private final ObjectMapper MAPPER = objectMapper();
private final ObjectMapper MAPPER = sharedMapper();
private final ObjectReader R = MAPPER.reader().without(DeserializationFeature.ACCEPT_FLOAT_AS_INT);

public void testDoubleToInt() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ static class WithBagOfValues2324 {
public Bag2324<Value2324> getValues() { return this.bagOfValues; }
public void setValues(Bag2324<Value2324> bagOfValues) { this.bagOfValues = bagOfValues; }
private Bag2324<Value2324> bagOfValues;
}
}

private final ObjectMapper MAPPER = objectMapper();
private final ObjectMapper MAPPER = sharedMapper();

// [databind#1804]
public void testDelegatingArray1804() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.math.BigInteger;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.databind.BaseMapTest;
Expand All @@ -16,7 +17,11 @@
*/
public class NumberSerTest extends BaseMapTest
{
private final ObjectMapper MAPPER = objectMapper();
private final ObjectMapper MAPPER = sharedMapper();

private final ObjectMapper NON_EMPTY_MAPPER = newJsonMapper()
.setDefaultPropertyInclusion(JsonInclude.Include.NON_EMPTY)
;

static class IntWrapper {
public int i;
Expand Down Expand Up @@ -114,6 +119,15 @@ public void testNumbersAsString() throws Exception
assertEquals(aposToQuotes("{'value':'123456'}"), MAPPER.writeValueAsString(new BigIntegerAsString()));
}

public void testNumbersAsStringNonEmpty() throws Exception
{
assertEquals(aposToQuotes("{'value':'3'}"), NON_EMPTY_MAPPER.writeValueAsString(new IntAsString()));
assertEquals(aposToQuotes("{'value':'4'}"), NON_EMPTY_MAPPER.writeValueAsString(new LongAsString()));
assertEquals(aposToQuotes("{'value':'-0.5'}"), NON_EMPTY_MAPPER.writeValueAsString(new DoubleAsString()));
assertEquals(aposToQuotes("{'value':'0.25'}"), NON_EMPTY_MAPPER.writeValueAsString(new BigDecimalAsString()));
assertEquals(aposToQuotes("{'value':'123456'}"), NON_EMPTY_MAPPER.writeValueAsString(new BigIntegerAsString()));
}

public void testConfigOverridesForNumbers() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
Expand Down

0 comments on commit c7ff8f6

Please sign in to comment.