|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.core.*;
|
4 | 4 | import com.fasterxml.jackson.databind.JsonNode;
|
| 5 | +import com.fasterxml.jackson.databind.JsonSerializable; |
5 | 6 | import com.fasterxml.jackson.databind.SerializerProvider;
|
6 | 7 | import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
7 | 8 | import com.fasterxml.jackson.databind.util.RawValue;
|
|
10 | 11 | import java.math.BigDecimal;
|
11 | 12 | import java.util.ArrayList;
|
12 | 13 | import java.util.Collection;
|
| 14 | +import java.util.Comparator; |
13 | 15 | import java.util.Iterator;
|
14 | 16 | import java.util.List;
|
15 | 17 |
|
@@ -98,30 +100,55 @@ public JsonNode path(int index) {
|
98 | 100 | }
|
99 | 101 | return MissingNode.getInstance();
|
100 | 102 | }
|
101 |
| - |
| 103 | + |
| 104 | + @Override |
| 105 | + public boolean equals(Comparator<JsonNode> comparator, JsonNode o) |
| 106 | + { |
| 107 | + if (!(o instanceof ArrayNode)) { |
| 108 | + return false; |
| 109 | + } |
| 110 | + ArrayNode other = (ArrayNode) o; |
| 111 | + final int len = _children.size(); |
| 112 | + if (other.size() != len) { |
| 113 | + return false; |
| 114 | + } |
| 115 | + List<JsonNode> l1 = _children; |
| 116 | + List<JsonNode> l2 = other._children; |
| 117 | + for (int i = 0; i < len; ++i) { |
| 118 | + if (comparator.compare(l1.get(i), l2.get(i)) != 0) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + } |
| 122 | + return true; |
| 123 | + } |
| 124 | + |
102 | 125 | /*
|
103 | 126 | /**********************************************************
|
104 | 127 | /* Public API, serialization
|
105 | 128 | /**********************************************************
|
106 | 129 | */
|
107 | 130 |
|
108 | 131 | @Override
|
109 |
| - public void serialize(JsonGenerator jg, SerializerProvider provider) throws IOException, JsonProcessingException |
| 132 | + public void serialize(JsonGenerator f, SerializerProvider provider) throws IOException |
110 | 133 | {
|
111 |
| - final List<JsonNode> c = _children; |
112 |
| - final int size = c.size(); |
113 |
| - jg.writeStartArray(size); |
| 134 | + final List<JsonNode> c = _children; |
| 135 | + final int size = c.size(); |
| 136 | + f.writeStartArray(size); |
114 | 137 | for (int i = 0; i < size; ++i) { // we'll typically have array list
|
115 |
| - // Can we trust that all nodes will always extend BaseJsonNode? Or if not, |
116 |
| - // at least implement JsonSerializable? Let's start with former, change if must |
117 |
| - ((BaseJsonNode) c.get(i)).serialize(jg, provider); |
| 138 | + // For now, assuming it's either BaseJsonNode, JsonSerializable |
| 139 | + JsonNode n = c.get(i); |
| 140 | + if (n instanceof BaseJsonNode) { |
| 141 | + ((BaseJsonNode) n).serialize(f, provider); |
| 142 | + } else { |
| 143 | + ((JsonSerializable) n).serialize(f, provider); |
| 144 | + } |
118 | 145 | }
|
119 |
| - jg.writeEndArray(); |
| 146 | + f.writeEndArray(); |
120 | 147 | }
|
121 | 148 |
|
122 | 149 | @Override
|
123 | 150 | public void serializeWithType(JsonGenerator jg, SerializerProvider provider, TypeSerializer typeSer)
|
124 |
| - throws IOException, JsonProcessingException |
| 151 | + throws IOException |
125 | 152 | {
|
126 | 153 | typeSer.writeTypePrefixForArray(this, jg);
|
127 | 154 | for (JsonNode n : _children) {
|
|
0 commit comments