use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.
the class IngraphDashboardConfigResource method viewDashboardConfigs.
@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String viewDashboardConfigs(@DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("100") @QueryParam("jtPageSize") int jtPageSize) {
List<IngraphDashboardConfigDTO> ingraphDashboardConfigDTOs = ingraphDashboardConfigDAO.findAll();
List<IngraphDashboardConfigDTO> subList = Utils.sublist(ingraphDashboardConfigDTOs, jtStartIndex, jtPageSize);
ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
return rootNode.toString();
}
use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.
the class JsonResponseUtil method buildResponseJSON.
public static ObjectNode buildResponseJSON(Object obj) {
ObjectNode rootNode = MAPPER.getNodeFactory().objectNode();
rootNode.put("Result", "OK");
JsonNode node = MAPPER.convertValue(obj, JsonNode.class);
rootNode.put("Record", node);
return rootNode;
}
use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.
the class JsonResponseUtil method buildResponseJSON.
public static ObjectNode buildResponseJSON(List<? extends Object> list) {
ObjectNode rootNode = MAPPER.getNodeFactory().objectNode();
ArrayNode resultArrayNode = MAPPER.createArrayNode();
rootNode.put("Result", "OK");
for (Object obj : list) {
JsonNode node = MAPPER.convertValue(obj, JsonNode.class);
resultArrayNode.add(node);
}
rootNode.put("Records", resultArrayNode);
return rootNode;
}
use of org.codehaus.jackson.node.ObjectNode in project neo4j by neo4j.
the class AbstractRESTInteraction method getValue.
private Object getValue(JsonNode valueNode) {
Object value;
if (valueNode instanceof TextNode) {
value = valueNode.asText();
} else if (valueNode instanceof ObjectNode) {
value = mapValue(valueNode.getFieldNames(), valueNode);
} else if (valueNode instanceof ArrayNode) {
ArrayNode aNode = (ArrayNode) valueNode;
ArrayList<String> listValue = new ArrayList<>(aNode.size());
for (int j = 0; j < aNode.size(); j++) {
listValue.add(aNode.get(j).asText());
}
value = listValue;
} else if (valueNode instanceof IntNode) {
value = valueNode.getIntValue();
} else if (valueNode instanceof LongNode) {
value = valueNode.getLongValue();
} else if (valueNode.isNull()) {
return null;
} else {
throw new RuntimeException(String.format("Unhandled REST value type '%s'. Need String (TextNode), List (ArrayNode), Object (ObjectNode), long (LongNode), or int (IntNode).", valueNode.getClass()));
}
return value;
}
use of org.codehaus.jackson.node.ObjectNode in project perun by CESNET.
the class OIDC method replaceAttrsInJsonTree.
private JsonNode replaceAttrsInJsonTree(PerunSession sess, User user, JsonNode node) throws InternalErrorException, WrongAttributeAssignmentException, PrivilegeException, UserNotExistsException {
ObjectMapper mapper = new ObjectMapper();
if (!node.isObject()) {
if (node.isTextual()) {
Matcher attrMatcher = attrRegex.matcher(node.getTextValue());
if (attrMatcher.matches()) {
try {
Object value = sess.getPerun().getAttributesManager().getAttribute(sess, user, node.getTextValue()).getValue();
if (value != null) {
return mapper.convertValue(value, JsonNode.class);
} else {
log.info("Attribute " + node.getTextValue() + " is not present for user " + user);
return NullNode.getInstance();
}
} catch (AttributeNotExistsException e) {
log.warn("Attribute " + node.getTextValue() + " does not exists");
return null;
}
}
}
return node;
} else {
ObjectNode object = (ObjectNode) node;
ObjectNode userinfo = mapper.createObjectNode();
Iterator<Map.Entry<String, JsonNode>> fieldsIterator = object.getFields();
while (fieldsIterator.hasNext()) {
Map.Entry<String, JsonNode> child = fieldsIterator.next();
JsonNode result = replaceAttrsInJsonTree(sess, user, child.getValue());
if (result != null) {
userinfo.put(child.getKey(), result);
}
}
if (userinfo.size() == 0) {
return null;
} else {
return userinfo;
}
}
}
Aggregations