Skip to content

Commit

Permalink
fix: don't display decimals in scientific notation in CLI (#4723)
Browse files Browse the repository at this point in the history
fixes: #4722

This change sees decimals being returned by the rest api avoiding use of scientific notation. For example, a decimal such as `100` will be returned as `100` and not `1e+2`.

The CLI just displays what it given.

Co-authored-by: Andy Coates <[email protected]>
  • Loading branch information
big-andy-coates and big-andy-coates authored Mar 10, 2020
1 parent 6cdd753 commit 3626f42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public enum JsonMapper {
mapper.registerModule(new KsqlTypesSerializationModule());
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
mapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.math.BigDecimal;
import org.junit.Test;

public class JsonMapperTest {
Expand All @@ -36,4 +37,13 @@ public void shouldNotAutoCloseTarget() {
public void shouldIgnoreUnknownProperties() {
assertThat(OBJECT_MAPPER.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES), is(false));
}

@Test
public void shouldNotUseScientificNotationWhenSerializingDecimals() throws Exception {
// When:
final String result = OBJECT_MAPPER.writeValueAsString(new BigDecimal("1e+1"));

// Then:
assertThat(result, is("10"));
}
}

0 comments on commit 3626f42

Please sign in to comment.