|
|
|
@ -12,6 +12,7 @@ import com.jayway.jsonpath.JsonPathException;
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.Iterator; |
|
|
|
@ -153,10 +154,11 @@ public class JacksonJsonNodeJsonProvider extends AbstractJsonProvider {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void setProperty(Object obj, Object key, Object value) { |
|
|
|
|
if (isMap(obj)) |
|
|
|
|
toJsonObject(obj).put(key.toString(), createJsonElement(value)); |
|
|
|
|
else { |
|
|
|
|
ArrayNode array = toJsonArray(obj); |
|
|
|
|
// jlolling: Bug: #211 avoid create cloned nodes
|
|
|
|
|
if (isMap(obj)) { |
|
|
|
|
setValueInObjectNode((ObjectNode) obj, key, value); |
|
|
|
|
} else { |
|
|
|
|
ArrayNode array = (ArrayNode) obj; |
|
|
|
|
int index; |
|
|
|
|
if (key != null) { |
|
|
|
|
index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString()); |
|
|
|
@ -171,9 +173,6 @@ public class JacksonJsonNodeJsonProvider extends AbstractJsonProvider {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
public void removeProperty(Object obj, Object key) { |
|
|
|
|
if (isMap(obj)) |
|
|
|
|
toJsonObject(obj).remove(key.toString()); |
|
|
|
@ -226,8 +225,17 @@ public class JacksonJsonNodeJsonProvider extends AbstractJsonProvider {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private JsonNode createJsonElement(Object o) { |
|
|
|
|
if (o != null) { |
|
|
|
|
// jlolling: avoid creating a cloned node: bug #211
|
|
|
|
|
if (o instanceof JsonNode) { |
|
|
|
|
return (JsonNode) o; |
|
|
|
|
} else { |
|
|
|
|
return objectMapper.valueToTree(o); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ArrayNode toJsonArray(Object o) { |
|
|
|
|
return (ArrayNode) o; |
|
|
|
@ -237,5 +245,33 @@ public class JacksonJsonNodeJsonProvider extends AbstractJsonProvider {
|
|
|
|
|
return (ObjectNode) o; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setValueInObjectNode(ObjectNode objectNode, Object key, Object value) { |
|
|
|
|
// jlolling: necessary to avoid deprecated methods and to avoid creating a cloned node. Bug: #211
|
|
|
|
|
if (value instanceof JsonNode) { |
|
|
|
|
objectNode.set(key.toString(), (JsonNode) value); |
|
|
|
|
} else if (value instanceof String) { |
|
|
|
|
objectNode.put(key.toString(), (String) value); |
|
|
|
|
} else if (value instanceof Integer) { |
|
|
|
|
objectNode.put(key.toString(), (Integer) value); |
|
|
|
|
} else if (value instanceof Long) { |
|
|
|
|
objectNode.put(key.toString(), (Long) value); |
|
|
|
|
} else if (value instanceof Short) { |
|
|
|
|
objectNode.put(key.toString(), (Short) value); |
|
|
|
|
} else if (value instanceof Double) { |
|
|
|
|
objectNode.put(key.toString(), (Double) value); |
|
|
|
|
} else if (value instanceof Float) { |
|
|
|
|
objectNode.put(key.toString(), (Float) value); |
|
|
|
|
} else if (value instanceof BigDecimal) { |
|
|
|
|
objectNode.put(key.toString(), (BigDecimal) value); |
|
|
|
|
} else if (value instanceof Boolean) { |
|
|
|
|
objectNode.put(key.toString(), (Boolean) value); |
|
|
|
|
} else if (value instanceof byte[]) { |
|
|
|
|
objectNode.put(key.toString(), (byte[]) value); |
|
|
|
|
} else if (value == null) { |
|
|
|
|
objectNode.remove(key.toString()); |
|
|
|
|
} else { |
|
|
|
|
throw new IllegalArgumentException("Cannot handle object type: " + value.getClass().getName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|