Search in sources :

Example 76 with JsonMappingException

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");
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Text(org.apache.hadoop.io.Text) JsonParseException(com.fasterxml.jackson.core.JsonParseException) File(java.io.File) Map(java.util.Map) Credentials(org.apache.hadoop.security.Credentials)

Example 77 with JsonMappingException

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");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 78 with JsonMappingException

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);
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException)

Example 79 with JsonMappingException

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;
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 80 with JsonMappingException

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());
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)140 IOException (java.io.IOException)68 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 JsonParseException (com.fasterxml.jackson.core.JsonParseException)52 Test (org.junit.Test)31 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)19 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)14 Map (java.util.Map)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 File (java.io.File)9 InputStream (java.io.InputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 List (java.util.List)7 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 Response (javax.ws.rs.core.Response)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)5