use of com.fasterxml.jackson.databind.JsonMappingException in project hadoop by apache.
the class JobSubmitter method readTokensFromFiles.
@SuppressWarnings("unchecked")
private void readTokensFromFiles(Configuration conf, Credentials credentials) throws IOException {
// add tokens and secrets coming from a token storage file
String binaryTokenFilename = conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY);
if (binaryTokenFilename != null) {
Credentials binary = Credentials.readTokenStorageFile(FileSystem.getLocal(conf).makeQualified(new Path(binaryTokenFilename)), conf);
credentials.addAll(binary);
}
// add secret keys coming from a json file
String tokensFileName = conf.get("mapreduce.job.credentials.json");
if (tokensFileName != null) {
LOG.info("loading user's secret keys from " + tokensFileName);
String localFileName = new Path(tokensFileName).toUri().getPath();
try {
// read JSON
Map<String, String> nm = READER.readValue(new File(localFileName));
for (Map.Entry<String, String> ent : nm.entrySet()) {
credentials.addSecretKey(new Text(ent.getKey()), ent.getValue().getBytes(Charsets.UTF_8));
}
} catch (JsonMappingException | JsonParseException e) {
LOG.warn("couldn't parse Token Cache JSON file with user secret keys");
}
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project bagheera by mozilla-metrics.
the class SequenceFileSink method addTimestampToJson.
public byte[] addTimestampToJson(byte[] data, long timestamp) throws IOException {
// TODO: add metrics/counters for failures
try {
ObjectNode document = jsonMapper.readValue(data, ObjectNode.class);
document.put(SINK_TIMESTAMP_FIELD, timestamp);
return (jsonMapper.writeValueAsBytes(document));
} catch (JsonParseException e) {
LOG.error("Invalid JSON", e);
LOG.debug(data);
} catch (JsonMappingException e) {
LOG.error("Invalid JSON", e);
LOG.debug(data);
}
throw new IOException("Invalid JSON");
}
use of com.fasterxml.jackson.databind.JsonMappingException in project uPortal by Jasig.
the class JacksonColumnMapper method toNonNullValue.
@Override
public final String toNonNullValue(Object value) {
try {
final Class<? extends Object> type = value.getClass();
final ObjectWriter typeWriter = typedObjectWriters.getUnchecked(type);
final String valueAsString = typeWriter.writeValueAsString(value);
return objectWriter.writeValueAsString(new JsonWrapper(type, valueAsString));
} catch (JsonGenerationException e) {
throw new IllegalArgumentException("Could not write to JSON: " + value, e);
} catch (JsonMappingException e) {
throw new IllegalArgumentException("Could not write to JSON: " + value, e);
} catch (IOException e) {
throw new IllegalArgumentException("Could not write to JSON: " + value, e);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project OpenAM by OpenRock.
the class ConditionTypesResource method jsonify.
/**
* Transforms a subclass of {@link EntitlementCondition} in to a JsonSchema representation.
* This schema is then combined with the Condition's name (taken as the resourceId) and all this is
* compiled together into a new {@link JsonValue} object until "title" and "config" fields respectively.
*
* @param conditionClass The class whose schema to produce.
* @param resourceId The ID of the resource to return
* @return A JsonValue containing the schema of the EntitlementCondition
*/
private JsonValue jsonify(Class<? extends EntitlementCondition> conditionClass, String resourceId, boolean logical) {
try {
final JsonSchema schema = mapper.generateJsonSchema(conditionClass);
//this will remove the 'name' attribute from those conditions which incorporate it unnecessarily
final JsonNode node = schema.getSchemaNode().get("properties");
if (node instanceof ObjectNode) {
final ObjectNode alter = (ObjectNode) node;
alter.remove("name");
}
return JsonValue.json(JsonValue.object(JsonValue.field(JSON_OBJ_TITLE, resourceId), JsonValue.field(JSON_OBJ_LOGICAL, logical), JsonValue.field(JSON_OBJ_CONFIG, schema)));
} catch (JsonMappingException e) {
if (debug.errorEnabled()) {
debug.error("ConditionTypesResource :: JSONIFY - Error applying " + "jsonification to the Condition class representation.", e);
}
return null;
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project camel by apache.
the class MultiSelectPicklistDeserializer method deserialize.
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
// validate enum class
if (enumClass == null) {
throw new JsonMappingException(jp, "Unable to parse unknown pick-list type");
}
final String listValue = jp.getText();
try {
// parse the string of the form value1;value2;...
final String[] value = listValue.split(";");
final int length = value.length;
final Object resultArray = Array.newInstance(enumClass, length);
for (int i = 0; i < length; i++) {
// use factory method to create object
Array.set(resultArray, i, factoryMethod.invoke(null, value[i].trim()));
}
return resultArray;
} catch (Exception e) {
throw new JsonParseException(jp, "Exception reading multi-select pick list value", jp.getCurrentLocation());
}
}
Aggregations