org.mockserver.serialization.JsonArraySerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-core Show documentation
Show all versions of mockserver-core Show documentation
Functionality used by all MockServer modules for matching and expectations
package org.mockserver.serialization;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.github.fge.jackson.JacksonUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* @author jamesdbloom
*/
public class JsonArraySerializer {
private static final ObjectMapper objectMapper = ObjectMapperFactory.createObjectMapper();
public List returnJSONObjects(String jsonArray) {
List arrayItems = new ArrayList();
try {
JsonNode jsonNode = objectMapper.readTree(jsonArray);
if (jsonNode instanceof ArrayNode) {
for (JsonNode arrayElement : jsonNode) {
arrayItems.add(JacksonUtils.prettyPrint(arrayElement));
}
} else {
arrayItems.add(JacksonUtils.prettyPrint(jsonNode));
}
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return arrayItems;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy