Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.json.JsonMapper;
Expand Down Expand Up @@ -139,6 +140,7 @@ private static final class JsonPrettyPrinter implements PrettyPrinter {

private final ObjectMapper objectMapper = JsonMapper.builder()
.enable(SerializationFeature.INDENT_OUTPUT)
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
.build();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.jspecify.annotations.Nullable;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.json.JsonMapper;
Expand All @@ -31,7 +32,9 @@
public class FieldPathPayloadSubsectionExtractor
implements PayloadSubsectionExtractor<FieldPathPayloadSubsectionExtractor> {

private static final ObjectMapper objectMapper = new ObjectMapper();
private static final ObjectMapper objectMapper = JsonMapper.builder()
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
.build();

private static final ObjectMapper prettyPrintingOjectMapper = JsonMapper.builder()
.enable(SerializationFeature.INDENT_OUTPUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ void prettyPrintJson() {
.isEqualTo(String.format("{%n \"a\" : 5%n}").getBytes());
}

@Test
void prettyPrintJsonPreservesNumbers() {
String content = "{\"a\":10.50,\"b\":0.1000000000000000055511151231257827,\"c\":12345678901234567890.123}";
assertThat(new String(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null)))
.isEqualTo(String.format("{%n \"a\" : 10.50,%n \"b\" : 0.1000000000000000055511151231257827,%n"
+ " \"c\" : 12345678901234567890.123%n}"));
}

@Test
void prettyPrintXml() {
assertThat(new PrettyPrintingContentModifier()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ void extractedSubsectionIsNotPrettyPrintedWhenInputIsNotPrettyPrinted() throws J
assertThat(new String(extractedSubsection)).isEqualTo(new String(subsection));
}

@Test
void extractedSubsectionPreservesNumbers() {
byte[] extractedSubsection = new FieldPathPayloadSubsectionExtractor("a").extractSubsection(
"{\"a\":{\"b\":10.50,\"c\":0.1000000000000000055511151231257827,\"d\":12345678901234567890.123}}"
.getBytes(),
MediaType.APPLICATION_JSON);
assertThat(new String(extractedSubsection))
.isEqualTo("{\"b\":10.50,\"c\":0.1000000000000000055511151231257827,\"d\":12345678901234567890.123}");
}

@Test
void extractNonExistentSubsection() {
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a.c")
Expand Down
Loading