19 package org.sleuthkit.autopsy.integrationtesting.config;
21 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
22 import com.fasterxml.jackson.core.JsonParser;
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import com.fasterxml.jackson.databind.DeserializationContext;
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
27 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
28 import com.fasterxml.jackson.databind.node.ArrayNode;
29 import com.fasterxml.jackson.databind.node.ObjectNode;
30 import com.fasterxml.jackson.databind.node.TextNode;
31 import com.fasterxml.jackson.databind.node.ValueNode;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.Iterator;
36 import java.util.LinkedHashMap;
37 import java.util.List;
43 @JsonIgnoreProperties(ignoreUnknown =
true)
44 @JsonDeserialize(
using = ParameterizedResourceConfig.ParameterizedResourceConfigDeserializer.class)
56 private static final long serialVersionUID = 1L;
75 public ParameterizedResourceConfig
deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
76 JsonNode node = jp.getCodec().readTree(jp);
81 }
else if (node instanceof TextNode) {
83 return new ParameterizedResourceConfig(node.textValue());
86 JsonNode resourceNode = node.get(
"resource");
87 String resource = (resourceNode != null) ? resourceNode.asText() : null;
89 Map<String, Object> parameters = null;
90 JsonNode parametersNode = node.get(
"parameters");
91 if (parametersNode != null && parametersNode.isObject()) {
92 parameters = readMap((ObjectNode) parametersNode);
95 return new ParameterizedResourceConfig(resource, parameters);
105 Map<String, Object> readMap(ObjectNode node) {
106 Map<String, Object> jsonObject =
new LinkedHashMap<>();
107 Iterator<Map.Entry<String, JsonNode>> keyValIter = node.fields();
108 while (keyValIter.hasNext()) {
109 Map.Entry<String, JsonNode> keyVal = keyValIter.next();
110 jsonObject.put(keyVal.getKey(), readItem(keyVal.getValue()));
121 List<Object> readList(ArrayNode node) {
122 List<Object> objArr =
new ArrayList<>();
123 for (JsonNode childNode : node) {
124 objArr.add(readItem(childNode));
136 Object readJsonPrimitive(ValueNode vNode) {
137 if (vNode.isTextual()) {
138 return vNode.asText();
139 }
else if (vNode.isBoolean()) {
140 return vNode.asBoolean();
141 }
else if (vNode.isLong()) {
142 return vNode.asLong();
143 }
else if (vNode.isInt()) {
144 return vNode.asInt();
145 }
else if (vNode.isDouble()) {
146 return vNode.asDouble();
158 Object readItem(JsonNode node) {
163 if (node.isObject()) {
164 return readMap((ObjectNode) node);
165 }
else if (node.isArray()) {
166 return readList((ArrayNode) node);
167 }
else if (node.isValueNode()) {
168 return readJsonPrimitive((ValueNode) node);
185 this.resource = resource;
186 this.parameters = (parameters == null) ? Collections.emptyMap() : parameters;
195 this(resource, null);
211 return parameters == null ? Collections.emptyMap() : Collections.unmodifiableMap(parameters);
ParameterizedResourceConfig(String resource)
Map< String, Object > getParameters()
final Map< String, Object > parameters
ParameterizedResourceConfigDeserializer()
ParameterizedResourceConfigDeserializer(Class<?> vc)
ParameterizedResourceConfig(String resource, Map< String, Object > parameters)
ParameterizedResourceConfig deserialize(JsonParser jp, DeserializationContext ctxt)