use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project ORCID-Source by ORCID.
the class OrcidJacksonJaxbJsonProviderPretty method readFrom.
/**
* This adds a validation step when converting JSON into ORCID models.
*/
@Override
public Object readFrom(Class<Object> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5) throws IOException {
Object o = null;
try {
o = super.readFrom(arg0, arg1, arg2, arg3, arg4, arg5);
} catch (JsonMappingException e) {
Map<String, String> params = new HashMap<>();
params.put("error", e.getMessage());
throw new InvalidJSONException(params);
}
if (jsonInputValidator.canValidate(o.getClass())) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String apiVersion = (String) requestAttributes.getAttribute(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
if (apiVersion != null && apiVersion.equals("2.1")) {
jsonInputValidator.validate2_1APIJSONInput(o);
} else {
jsonInputValidator.validateJSONInput(o);
}
}
return o;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project service-proxy by membrane.
the class EtcdResponse method getDirectories.
@SuppressWarnings("unchecked")
public ArrayList<String> getDirectories() {
JsonParser par = getParser(body);
String baseKey = originalRequest.baseKey;
String module = originalRequest.module;
ArrayList<String> directories = new ArrayList<String>();
Map<String, Object> respData = null;
try {
respData = new ObjectMapper().readValue(par, Map.class);
} catch (JsonParseException e) {
} catch (JsonMappingException e) {
} catch (IOException e) {
}
if (respData.containsKey("node")) {
LinkedHashMap<String, Object> nodeJson = (LinkedHashMap<String, Object>) respData.get("node");
if (nodeJson.containsKey("nodes")) {
ArrayList<Object> nodesArray = (ArrayList<Object>) nodeJson.get("nodes");
for (Object object : nodesArray) {
LinkedHashMap<String, Object> dirs = (LinkedHashMap<String, Object>) object;
if (dirs.containsKey("key")) {
String servicePath = dirs.get("key").toString();
String uuid = servicePath.replaceAll(baseKey + module, "");
directories.add(uuid);
}
}
}
}
return directories;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project n4js by eclipse.
the class PingSessionResource method createEvent.
@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String body) throws ClientResourceException {
if (isNullOrEmpty(body))
throw new ClientResourceException(SC_BAD_REQUEST);
final Map<?, ?> values = newHashMap();
try {
values.putAll(mapper.readValue(body, Map.class));
} catch (JsonMappingException | JsonParseException e) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} catch (final IOException e) {
throw new ClientResourceException(SC_BAD_REQUEST);
}
final Object value = values.get(TIMEOUT_KEY);
// incorrect schema
if (null == value) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
}
final Object comment = values.get(COMMENT_KEY);
try {
final long timeout = parseLong(Objects.toString(value));
return new SessionPingedEvent(sessionId, timeout, null == comment ? null : valueOf(comment));
} catch (final NumberFormatException e) {
// although schema was valid the data was indeed invalid
throw new ClientResourceException(SC_BAD_REQUEST);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project n4js by eclipse.
the class PingTestResource method createEvent.
@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String testId, final String body) throws ClientResourceException {
if (isNullOrEmpty(body))
throw new ClientResourceException(SC_BAD_REQUEST);
final Map<?, ?> values = newHashMap();
try {
values.putAll(mapper.readValue(body, Map.class));
} catch (JsonMappingException | JsonParseException e) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} catch (final IOException e) {
throw new ClientResourceException(SC_BAD_REQUEST);
}
final Object value = values.get(TIMEOUT_KEY);
// incorrect schema
if (null == value) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
}
final Object comment = values.get(COMMENT_KEY);
try {
final long timeout = parseLong(Objects.toString(value));
return new TestPingedEvent(sessionId, testId, timeout, null == comment ? null : valueOf(comment));
} catch (final NumberFormatException e) {
// although schema was valid the data was indeed invalid
throw new ClientResourceException(SC_BAD_REQUEST);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method readFragment.
private static Map<String, Object> readFragment(File file, String ext) throws IOException {
ObjectMapper mapper = new ObjectMapper("json".equals(ext) ? new JsonFactory() : new YAMLFactory());
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
};
try {
Map<String, Object> ret = mapper.readValue(file, typeRef);
return ret != null ? ret : new HashMap<String, Object>();
} catch (JsonProcessingException e) {
throw new JsonMappingException(String.format("[%s] %s", file, e.getMessage()), e.getLocation(), e);
}
}
Aggregations