Skip to content

Commit

Permalink
add number test where num starts with a dot (#4436)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored Mar 22, 2024
1 parent b041941 commit fc67817
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,12 @@

public class TestBigNumbers extends BaseMapTest
{
static class BigDecimalWrapper {
BigDecimal number;

public BigDecimalWrapper() {}

public BigDecimalWrapper(BigDecimal number) {
this.number = number;
}

public void setNumber(BigDecimal number) {
this.number = number;
}
}

static class BigIntegerWrapper {
BigInteger number;

public BigIntegerWrapper() {}

public BigIntegerWrapper(BigInteger number) {
this.number = number;
}
public BigInteger number;
}

public void setNumber(BigInteger number) {
this.number = number;
}
static class BigDecimalWrapper {
public BigDecimal number;
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.fasterxml.jackson.databind.deser.jdk;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.assertEquals;

// @since 2.16.3
public class BigDecimalDeser4435Test
{
static class BigDecimalWrapper {
public BigDecimal number;
}

/*
/**********************************************************
/* Tests
/**********************************************************
*/

private final ObjectMapper MAPPER = JsonMapper.builder().build();

@Test
public void testNumberStartingWithDot() throws Exception
{
String num = ".555555555555555555555555555555";
BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class);
assertEquals(new BigDecimal(num), w.number);
}

@Test
public void testNumberStartingWithMinusDot() throws Exception
{
String num = "-.555555555555555555555555555555";
BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class);
assertEquals(new BigDecimal(num), w.number);
}

@Test
public void testNumberStartingWithPlusDot() throws Exception
{
String num = "+.555555555555555555555555555555";
BigDecimalWrapper w = MAPPER.readValue("{\"number\":\"" + num + "\"}", BigDecimalWrapper.class);
assertEquals(new BigDecimal(num), w.number);
}
}

0 comments on commit fc67817

Please sign in to comment.