Skip to content

Commit

Permalink
Enableling source in location here and there.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Nov 22, 2023
1 parent 91c4978 commit c8d4d79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import org.slf4j.event.Level;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;

import com.fasterxml.jackson.core.StreamReadFeature;
import com.fasterxml.jackson.databind.*;

import nl.vpro.jackson2.Jackson2Mapper;
Expand All @@ -35,7 +36,10 @@
@Slf4j
public class Jackson2TestUtil {

private static final ObjectMapper MAPPER = Jackson2Mapper.getPrettyStrictInstance();
private static final ObjectMapper MAPPER =
Jackson2Mapper.getPrettyStrictInstance();

private static final ObjectReader JSON_READER = MAPPER.readerFor(JsonNode.class).with(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION);


public static void assertJsonEquals(String pref, CharSequence expected, CharSequence actual) {
Expand All @@ -57,7 +61,7 @@ public static CharSequence prettify(CharSequence test) {
return null;
}
try {
JsonNode jsonNode = MAPPER.readTree(String.valueOf(test));
JsonNode jsonNode = JSON_READER.readTree(String.valueOf(test));
String pretty = MAPPER.writeValueAsString(jsonNode);
return pretty;
} catch (IOException e) {
Expand Down Expand Up @@ -153,14 +157,25 @@ public static <T> T roundTripAndSimilarAndEquals(ObjectMapper mapper, T input, S

public static <T> T assertJsonEquals(String actual, String expected, Class<T> typeReference) throws IOException {
assertJsonEquals("", expected, actual);
return MAPPER.readValue(actual, typeReference);
return objectReader(MAPPER, typeReference).readValue(actual, typeReference);
}


protected static <T> T roundTripAndSimilar(T input, String expected, JavaType typeReference, boolean remarshal) {
return roundTripAndSimilar(MAPPER, input, expected, typeReference, remarshal);
}

protected static ObjectReader objectReader(ObjectMapper mapper, JavaType typeReference) {
return mapper.readerFor(typeReference)
.with(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION);

}
protected static ObjectReader objectReader(ObjectMapper mapper, Class<?> typeReference) {
return mapper.readerFor(typeReference)
.with(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION);

}

@SneakyThrows
protected static <T> T roundTripAndSimilar(ObjectMapper mapper, T input, String expected, JavaType typeReference, boolean remarshall) {
String marshalled = marshallAndSimilar(mapper, input, expected);
Expand Down

0 comments on commit c8d4d79

Please sign in to comment.