DATAREST-887 - JsonPatchPatchHandler now uses external ObjectMapper.

The previously static ObjectMapper used by JsonPatchPatchHandler now has to be provided by clients instantiating the handler.

Original pull request: #224.
This commit is contained in:
Mathias Düsterhöft
2016-09-06 15:37:43 +02:00
committed by Oliver Gierke
parent 31c894e880
commit 0a6dcc9825
4 changed files with 10 additions and 5 deletions

View File

@@ -107,7 +107,7 @@ class JsonPatchHandler {
private Patch getPatchOperations(InputStream source) {
try {
return new JsonPatchPatchConverter().convert(mapper.readTree(source));
return new JsonPatchPatchConverter(mapper).convert(mapper.readTree(source));
} catch (Exception o_O) {
throw new HttpMessageNotReadableException(
String.format("Could not read PATCH operations! Expected %s!", RestMediaTypes.JSON_PATCH_JSON), o_O);

View File

@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* {@link LateObjectEvaluator} implementation that assumes values represented as JSON objects.
*
* @author Craig Walls
* @author Mathias Düsterhöft
*/
class JsonLateObjectEvaluator implements LateObjectEvaluator {

View File

@@ -33,9 +33,13 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
*/
public class JsonPatchPatchConverter implements PatchConverter<JsonNode> {
private static final ObjectMapper MAPPER = new ObjectMapper();
private final ObjectMapper mapper;
/**
public JsonPatchPatchConverter(ObjectMapper mapper) {
this.mapper = mapper;
}
/**
* Constructs a {@link Patch} object given a JsonNode.
*
* @param jsonNode a JsonNode containing the JSON Patch
@@ -99,7 +103,7 @@ public class JsonPatchPatchConverter implements PatchConverter<JsonNode> {
}
Object value = operation.getValue();
if (value != null) {
opNode.set("value", MAPPER.valueToTree(value));
opNode.set("value", mapper.valueToTree(value));
}
patchNode.add(opNode);
}

View File

@@ -113,7 +113,7 @@ public class JsonPatchTest {
ClassPathResource resource = new ClassPathResource(jsonPatchFile, getClass());
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readValue(resource.getInputStream(), JsonNode.class);
Patch patch = new JsonPatchPatchConverter().convert(node);
Patch patch = new JsonPatchPatchConverter(mapper).convert(node);
return patch;
}