forked from java-json-tools/json-patch
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJsonPatchOperationFactoryBase.java
More file actions
36 lines (31 loc) · 1.19 KB
/
JsonPatchOperationFactoryBase.java
File metadata and controls
36 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.github.fge.jsonpatch.operation;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JacksonUtils;
import com.github.fge.jsonpatch.JsonPatchException;
import com.github.fge.jsonpatch.JsonPatchMessages;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;
import java.io.IOException;
/**
* The JsonPatchOperationFactoryBase implements a few common operations
* for all JsonPatchOperationFactorys.
*/
public abstract class JsonPatchOperationFactoryBase implements JsonPatchOperationFactory
{
private static final MessageBundle BUNDLE
= MessageBundles.getBundle(JsonPatchMessages.class);
/**
* Gets the class of JsonPatchOperation that this factory will create.
* @return
*/
public abstract Class<? extends JsonPatchOperation> getOperationClass();
public JsonPatchOperation create(JsonNode node)
throws JsonPatchException
{
try {
return JacksonUtils.getReader().withType(getOperationClass()).readValue(node);
} catch (IOException e) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.deserFailed"), e);
}
}
}