use of org.codehaus.jackson.node.ArrayNode 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.ArrayNode 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.ArrayNode in project neo4j by neo4j.
the class EnterpriseAuthenticationIT method shouldHavePredefinedRoles.
@Test
public void shouldHavePredefinedRoles() throws Exception {
// Given
startServerWithConfiguredUser();
// When
String method = "POST";
String path = "db/data/transaction/commit";
HTTP.RawPayload payload = HTTP.RawPayload.quotedJson("{'statements':[{'statement':'CALL dbms.security.listRoles()'}]}");
HTTP.Response response = HTTP.withHeaders(HttpHeaders.AUTHORIZATION, challengeResponse("neo4j", "secret")).request(method, server.baseUri().resolve(path).toString(), payload);
// Then
assertThat(response.status(), equalTo(200));
ArrayNode errors = (ArrayNode) response.get("errors");
assertThat("Should have no errors", errors.size(), equalTo(0));
ArrayNode results = (ArrayNode) response.get("results");
ArrayNode data = (ArrayNode) results.get(0).get("data");
assertThat("Should have 4 predefined roles", data.size(), equalTo(4));
Stream<String> values = data.findValues("row").stream().map(row -> row.get(0).asText());
assertThat("Expected specific roles", values.collect(Collectors.toList()), hasItems("admin", "architect", "publisher", "reader"));
}
use of org.codehaus.jackson.node.ArrayNode in project oxTrust by GluuFederation.
the class SchemaTypeGroupSerializer method serialize.
@Override
public void serialize(Group group, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
log.info(" serialize() ");
try {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
JsonNode rootNode = mapper.convertValue(group, JsonNode.class);
Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
while (iterator.hasNext()) {
Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
if (rootNodeEntry.getValue() instanceof ObjectNode) {
// Definitely maybe in the near future
} else if (rootNodeEntry.getValue() instanceof ArrayNode) {
AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
if (rootNodeEntry.getKey().equalsIgnoreCase("members")) {
arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
List<String> referenceTypes = new ArrayList<String>();
referenceTypes.add("User");
arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
} else {
arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
}
arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
arrayNodeAttributeHolder.setUniqueness("server");
arrayNodeAttributeHolder.setType("string");
arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
arrayNodeAttributeHolder.setMutability("readOnly");
arrayNodeAttributeHolder.setReturned("always");
} else {
arrayNodeAttributeHolder.setType("complex");
}
List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
while (arrayNodeIterator.hasNext()) {
JsonNode jsonNode = arrayNodeIterator.next();
Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
while (arrayNodeMapIterator.hasNext()) {
Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
if (rootNodeEntry.getKey().equalsIgnoreCase("members") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
arrayNodeMapAttributeHolder.setName("$ref");
} else {
arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
}
arrayNodeMapAttributeHolder.setType("string");
arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
} else {
arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
}
arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
}
arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
attributeHolders.add(arrayNodeAttributeHolder);
}
} else {
if (!rootNodeEntry.getKey().equalsIgnoreCase("externalId")) {
AttributeHolder attributeHolder = new AttributeHolder();
attributeHolder.setName(rootNodeEntry.getKey());
if (rootNodeEntry.getValue().isBoolean()) {
attributeHolder.setType("boolean");
} else {
attributeHolder.setType("string");
}
attributeHolder.setDescription(rootNodeEntry.getKey());
attributeHolder.setRequired(Boolean.FALSE);
if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
attributeHolder.setUniqueness("server");
attributeHolder.setCaseExact(Boolean.TRUE);
attributeHolder.setMutability("readOnly");
attributeHolder.setReturned("always");
}
if (rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
attributeHolder.setReturned("always");
}
attributeHolders.add(attributeHolder);
}
}
}
GroupCoreSchema groupCoreSchema = (GroupCoreSchema) schemaType;
groupCoreSchema.setAttributeHolders(attributeHolders);
schemaType = groupCoreSchema;
} catch (Exception e) {
e.printStackTrace();
throw new IOException("Unexpected processing error; please check the Group class structure.");
}
}
use of org.codehaus.jackson.node.ArrayNode in project oxTrust by GluuFederation.
the class ExtensionDeserializer method deserialize.
@Override
public Extension deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
log.info(" deserialize() ");
try {
if (id == null || id.isEmpty()) {
throw new IllegalArgumentException("The URN cannot be null or empty");
}
JsonNode rootNode = jsonParser.readValueAsTree();
if (!rootNode.isObject()) {
throw new IllegalArgumentException("Extension is of wrong JSON type");
}
Extension.Builder extensionBuilder = new Extension.Builder(id);
Iterator<Map.Entry<String, JsonNode>> fieldIterator = rootNode.getFields();
while (fieldIterator.hasNext()) {
Map.Entry<String, JsonNode> entry = fieldIterator.next();
GluuAttribute gluuAttribute = attributeService.getAttributeByName(entry.getKey());
if (gluuAttribute != null) {
if (!(gluuAttribute.getOxSCIMCustomAttribute() != null && gluuAttribute.getOxSCIMCustomAttribute().equals(ScimCustomAtribute.TRUE))) {
log.info(" NOT A CUSTOM ATTRIBUTE: " + gluuAttribute.getName());
throw new IllegalArgumentException("NOT A CUSTOM ATTRIBUTE: " + gluuAttribute.getName());
}
GluuAttributeDataType attributeDataType = gluuAttribute.getDataType();
if ((gluuAttribute.getOxMultivaluedAttribute() != null) && gluuAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
if (entry.getValue() instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) entry.getValue();
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
List<String> stringList = Arrays.asList(mapper.readValue(arrayNode, String[].class));
extensionBuilder.setFieldAsList(entry.getKey(), stringList);
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
// For validation
List<Date> dateList = Arrays.asList(mapper.readValue(arrayNode, Date[].class));
extensionBuilder.setFieldAsList(entry.getKey(), Arrays.asList(mapper.readValue(arrayNode, String[].class)));
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
List<BigDecimal> numberList = Arrays.asList(mapper.readValue(arrayNode, BigDecimal[].class));
extensionBuilder.setFieldAsList(entry.getKey(), numberList);
} else {
log.info(" NO MATCH: attributeDataType.getDisplayName() = " + attributeDataType.getDisplayName());
throw new IllegalArgumentException("JSON type not supported: " + entry.getValue().toString());
}
} else {
throw new IllegalArgumentException("Attribute \"" + entry.getKey() + "\" is multi-valued but passed value is not of array type.");
}
} else {
if (entry.getValue() instanceof ArrayNode) {
throw new IllegalArgumentException("Attribute \"" + entry.getKey() + "\" is not multi-valued but passed value is of array type.");
} else {
if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
handleString(extensionBuilder, entry);
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
handleDateTime(extensionBuilder, entry);
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
handleNumber(extensionBuilder, entry);
} else {
log.info(" NO MATCH: attributeDataType.getDisplayName() = " + attributeDataType.getDisplayName());
throw new IllegalArgumentException("JSON type not supported: " + entry.getValue().toString());
}
}
}
} else {
throw new IllegalArgumentException("NOT FOUND: custom attribute = " + entry.getKey());
}
}
return extensionBuilder.build();
} catch (Exception e) {
e.printStackTrace();
throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
}
}
Aggregations