forked from java-json-tools/json-patch
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPathValueProperties.java
More file actions
87 lines (74 loc) · 2.42 KB
/
PathValueProperties.java
File metadata and controls
87 lines (74 loc) · 2.42 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.github.fge.jsonpatch.properties;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.github.fge.jsonpatch.JsonPatchMessages;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;
import java.io.IOException;
/**
*
*/
public class PathValueProperties
implements JsonPatchOperationProperties
{
protected static final MessageBundle BUNDLE
= MessageBundles.getBundle(JsonPatchMessages.class);
protected final String op;
protected final JsonPointer path;
@JsonSerialize
protected final JsonNode value;
/**
* @param op operation name
* @param path affected path
* @param value JSON value
*/
@JsonCreator
public PathValueProperties(@JsonProperty("op") final String op,
@JsonProperty("path") final JsonPointer path,
@JsonProperty("value") final JsonNode value)
{
this.op = op;
this.path = path;
this.value = value.deepCopy();
}
public String getOp()
{
return op;
}
public JsonPointer getPath()
{
return path;
}
public JsonNode getValue()
{
return value.deepCopy();
}
public final void serialize(final JsonGenerator jgen,
final SerializerProvider provider)
throws IOException, JsonProcessingException
{
jgen.writeStartObject();
jgen.writeStringField("op", op);
jgen.writeStringField("path", path.toString());
jgen.writeFieldName("value");
jgen.writeTree(value);
jgen.writeEndObject();
}
public final void serializeWithType(final JsonGenerator jgen,
final SerializerProvider provider, final TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
serialize(jgen, provider);
}
public final String toString()
{
return "op: " + op + "; path: \"" + path + "\"; value: " + value;
}
}