use of com.fasterxml.jackson.databind.JsonMappingException in project knox by apache.
the class JsonUtils method getMapFromJsonString.
public static Map<String, String> getMapFromJsonString(String json) {
Map<String, String> map = null;
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(factory);
TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {
};
try {
map = mapper.readValue(json, typeRef);
} catch (JsonParseException e) {
LOG.failedToGetMapFromJsonString(json, e);
} catch (JsonMappingException e) {
LOG.failedToGetMapFromJsonString(json, e);
} catch (IOException e) {
LOG.failedToGetMapFromJsonString(json, e);
}
return map;
}
use of com.fasterxml.jackson.databind.JsonMappingException in project core-util by WSO2Telco.
the class YamlReader method getConfiguration.
/**
* Gets the configuration.
*
* @return the configuration
*/
public static ConfigDTO getConfiguration() {
File file = new File(DEVICE_MGT_CONFIG_PATH);
ConfigDTO configPojo = new ConfigDTO();
// jackson databind
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
configPojo = mapper.readValue(file, ConfigDTO.class);
} catch (JsonParseException e) {
log.error("Yaml Parsing Error", e);
} catch (JsonMappingException e) {
log.error("Yaml Mapping Error", e);
} catch (IOException e) {
log.error("Yaml File Error", e);
}
return configPojo;
}
use of com.fasterxml.jackson.databind.JsonMappingException in project n4js by eclipse.
the class StartSessionResource method createEvent.
@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String body) throws ClientResourceException {
final Map<?, ?> values = newHashMap();
try {
if (!isNullOrEmpty(body)) {
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 Map<String, String> properties = newHashMap();
if (null != values.get(PROPERTIES)) {
if (!(values.get(PROPERTIES) instanceof Map)) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} else {
((Map<?, ?>) values.get(PROPERTIES)).entrySet().forEach(new Consumer<Entry<?, ?>>() {
@Override
public void accept(final Entry<?, ?> entry) {
properties.put(valueOf(entry.getKey()), valueOf(entry.getValue()));
}
});
}
}
return new SessionStartedEvent(sessionId, properties);
}
use of com.fasterxml.jackson.databind.JsonMappingException in project n4js by eclipse.
the class StartTestResource 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 Map<String, String> properties = newHashMap();
if (null != values.get(PROPERTIES)) {
if (!(values.get(PROPERTIES) instanceof Map)) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} else {
((Map<?, ?>) values.get(PROPERTIES)).entrySet().forEach(new Consumer<Entry<?, ?>>() {
@Override
public void accept(final Entry<?, ?> entry) {
properties.put(valueOf(entry.getKey()), valueOf(entry.getValue()));
}
});
}
}
try {
final long timeout = parseLong(valueOf(value));
return new TestStartedEvent(sessionId, testId, timeout, properties);
} catch (final NumberFormatException e) {
// although schema was valid the data was indeed invalid
throw new ClientResourceException(SC_BAD_REQUEST);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project underlx by underlx.
the class API method postPairRequest.
public Pair postPairRequest(PairRequest request) throws APIException {
try {
byte[] content = mapper.writeValueAsBytes(request);
InputStream is = postRequest(endpoint.resolve("pair"), content, false);
return mapper.readValue(is, Pair.class);
} catch (JsonParseException e) {
throw new APIException(e).addInfo("Parse exception");
} catch (JsonMappingException e) {
throw new APIException(e).addInfo("Mapping exception");
} catch (IOException e) {
throw new APIException(e).addInfo("IOException");
}
}
Aggregations