use of org.codehaus.jackson.JsonNode in project tdi-studio-se by Talend.
the class ExchangeUtils method parseJsonObject.
public static List parseJsonObject(String jsonContent, Class clazz) throws Exception {
// need factory for creating parser to use
List objList = new ArrayList();
// for 4.1.0 the is no json param on server ,so jsonContent is "wrong parameters for version"
if (!jsonContent.startsWith("[")) {
return objList;
}
JsonFactory jf = new JsonFactory();
JsonNode node = new ObjectMapper().reader().readTree(jf.createJsonParser(new StringReader(jsonContent)));
List<Object> list = new ObjectMapper().readValue(node.traverse(), List.class);
for (Object source : list) {
Object obj = clazz.newInstance();
BeanUtils.copyProperties(obj, source);
objList.add(obj);
}
return objList;
}
use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class JsonDeserializer method readInt.
@Override
public int readInt(String name) throws RpcException {
JsonNode node;
if (name == null) {
// The object is not under root, but directly in the response
node = root;
name = "root";
} else {
node = root.get(name);
}
if (node == null) {
throw new RpcException(RpcException.Type.MISSING_VALUE, name);
}
if (!node.isInt()) {
if (!node.isTextual()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as int");
} else {
try {
return Integer.parseInt(node.getTextValue());
} catch (NumberFormatException ex) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as int", ex);
}
}
}
return node.getIntValue();
}
use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class OIDC method getUserinfo.
private ObjectNode getUserinfo(final PerunSession sess, final User user, Collection<String> allowedScopes, Map<String, String> properties) throws InternalErrorException, PrivilegeException, UserNotExistsException, WrongAttributeAssignmentException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode userinfo = mapper.createObjectNode();
for (final String scope : allowedScopes) {
String property = properties.get(scope);
if (property == null || property.isEmpty()) {
log.info("No values are mapped to scope " + scope + ". Configure them in " + CONFIG_FILE);
continue;
}
try {
JsonNode claims = mapper.readTree(property);
if (!claims.isObject()) {
throw new InternalErrorException("Config file " + CONFIG_FILE + " is wrongly configured. Values have to be valid JSON objects.");
}
claims = replaceAttrsInJsonTree(sess, user, claims);
if (claims != null && claims.isObject()) {
userinfo.putAll((ObjectNode) claims);
}
} catch (IOException e) {
throw new InternalErrorException("Config file " + CONFIG_FILE + " is wrongly configured. Values have to be valid JSON objects.", e);
}
}
return userinfo;
}
use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class JsonDeserializer method readList.
@Override
public <T> List<T> readList(String name, Class<T> valueType) throws RpcException {
JsonNode node;
if (name == null) {
// The object is not under root, but directly in the response
node = root;
name = "root";
} else {
node = root.get(name);
}
if (node == null) {
throw new RpcException(RpcException.Type.MISSING_VALUE, name);
}
if (node.isNull()) {
return null;
}
if (!node.isArray()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<" + valueType.getSimpleName() + "> - not an array");
}
try {
List<T> list = new ArrayList<>(node.size());
for (JsonNode e : node) {
list.add(mapper.readValue(e, valueType));
}
return list;
} catch (IOException ex) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as List<" + valueType.getSimpleName() + ">", ex);
}
}
use of org.codehaus.jackson.JsonNode in project perun by CESNET.
the class JsonDeserializer method readArrayOfInts.
@Override
public int[] readArrayOfInts(String name) throws RpcException {
JsonNode node = root.get(name);
if (node == null) {
throw new RpcException(RpcException.Type.MISSING_VALUE, name);
}
if (node.isNull()) {
return null;
}
if (!node.isArray()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as int[] - not an array");
}
int[] array = new int[node.size()];
for (int i = 0; i < node.size(); ++i) {
JsonNode value = node.get(i);
if (!value.isInt()) {
throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as int");
}
array[i] = node.get(i).getIntValue();
}
return array;
}
Aggregations