Search in sources :

Example 81 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project gravel by gravel-st.

the class StringExtensions method parseAsJSONValue.

public static Map<String, Object> parseAsJSONValue(String src) {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode rootNode;
    try {
        rootNode = (ObjectNode) mapper.readValue(src, JsonNode.class);
    } catch (JsonParseException e) {
        throw new RuntimeException(e);
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    HashMap<String, Object> map = new HashMap<String, Object>();
    for (Iterator<Entry<String, JsonNode>> iter = rootNode.getFields(); iter.hasNext(); ) {
        Entry<String, JsonNode> field = iter.next();
        JsonNode value = field.getValue();
        Object o = jsonNodeAsSimpleObject(value);
        map.put(field.getKey(), o);
    }
    return map;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) HashMap(java.util.HashMap) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) Entry(java.util.Map.Entry) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 82 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project databus by linkedin.

the class DbusEventSerializable method getErrorEventFromDbusEvent.

public static DbusErrorEvent getErrorEventFromDbusEvent(DbusEventInternalReadable event) {
    if (!event.isErrorEvent()) {
        throw new RuntimeException("Event is expected to be an error event: " + event);
    }
    ByteBuffer valueBuffer = event.value();
    byte[] valueBytes = new byte[valueBuffer.limit()];
    valueBuffer.get(valueBytes);
    try {
        DbusErrorEvent errorEvent = DbusErrorEvent.createDbusErrorEvent(new String(valueBytes));
        return errorEvent;
    } catch (JsonParseException e) {
        throw new RuntimeException(e);
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ByteBuffer(java.nio.ByteBuffer)

Example 83 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project databus by linkedin.

the class ClusterCheckpointPersistenceProvider method getCheckpoint.

/**
 * internal function that fetches contents from Helix property store
 *
 * @param key
 * @return checkpoint or null
 */
private Checkpoint getCheckpoint(String key) {
    ZNRecord zn = _propertyStore.get(key, null, AccessOption.PERSISTENT);
    if (zn != null) {
        String v = zn.getSimpleField(KEY_CHECKPOINT);
        try {
            Checkpoint cp;
            cp = new Checkpoint(v);
            return cp;
        } catch (JsonParseException e) {
            LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
        } catch (JsonMappingException e) {
            LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
        } catch (IOException e) {
            LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
        }
    } else {
        LOG.error("No record for key = " + key);
    }
    return null;
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ZNRecord(org.apache.helix.ZNRecord)

Example 84 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project databus by linkedin.

the class PhysicalSourceConfigBuilder method build.

@Override
public PhysicalSourceStaticConfig[] build() throws InvalidConfigException {
    ObjectMapper mapper = new ObjectMapper();
    PhysicalSourceStaticConfig[] list = new PhysicalSourceStaticConfig[null == _fileNames ? 0 : _fileNames.length];
    if (_fileNames == null)
        return list;
    for (int i = 0; i < _fileNames.length; ++i) {
        File sourceJson = _fileNames[i];
        PhysicalSourceConfig pConfig = null;
        Exception e = null;
        try {
            pConfig = mapper.readValue(sourceJson, PhysicalSourceConfig.class);
        } catch (JsonParseException jpe) {
            e = jpe;
        } catch (JsonMappingException jme) {
            e = jme;
        } catch (IOException ioe) {
            e = ioe;
        }
        if (e != null || pConfig == null) {
            throw new InvalidConfigException(e);
        }
        pConfig.checkForNulls();
        LOG.info("Generated Physical source config: name= " + pConfig.getId());
        list[i] = pConfig.build();
    }
    /*
    for(PhysicalSourceStaticConfig pCfg : pConfigs) {
      for(LogicalSourceStaticConfig lSC : pCfg.getSources()) {
        config.setSourceName("" + lSC.getId(), lSC.getName());
      }
    }
    */
    return list;
}
Also used : PhysicalSourceStaticConfig(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig) PhysicalSourceConfig(com.linkedin.databus2.relay.config.PhysicalSourceConfig) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException) IOException(java.io.IOException)

Example 85 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project stanbol by apache.

the class AnalyzedTextParser method parseAnnotation.

private void parseAnnotation(Span span, String key, ObjectNode jValue) throws IOException {
    JsonNode jClass = jValue.path("class");
    if (!jClass.isTextual()) {
        log.warn("unable to parse Annotation {} because 'class' field " + "is not set or not a stringis no JSON object (ignored, json: {}", key, jValue);
        return;
    }
    Class<?> clazz;
    try {
        clazz = AnalyzedTextParser.class.getClassLoader().loadClass(jClass.getTextValue());
    } catch (ClassNotFoundException e) {
        log.warn("Unable to parse Annotation " + key + " because the 'class' " + jClass.getTextValue() + " of the " + "the value can not be resolved (ignored, json: " + jValue + ")", e);
        return;
    }
    ValueTypeParser<?> parser = this.valueTypeParserRegistry.getParser(clazz);
    Object value;
    if (parser != null) {
        value = parser.parse(jValue, span.getContext());
    } else {
        JsonNode valueNode = jValue.path("value");
        if (valueNode.isMissingNode()) {
            log.warn("unable to parse value for annotation {} because the " + "field 'value' is not present (ignored, json: {}", key, jValue);
            return;
        } else {
            try {
                value = mapper.treeToValue(valueNode, clazz);
            } catch (JsonParseException e) {
                log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
                return;
            } catch (JsonMappingException e) {
                log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
                return;
            }
        }
    }
    JsonNode jProb = jValue.path("prob");
    if (!jProb.isDouble()) {
        span.addValue(key, Value.value(value));
    } else {
        span.addValue(key, Value.value(value, jProb.getDoubleValue()));
    }
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.codehaus.jackson.JsonParseException)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)88 IOException (java.io.IOException)79 JsonParseException (org.codehaus.jackson.JsonParseException)53 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)36 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)27 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 Response (javax.ws.rs.core.Response)13 Map (java.util.Map)11 List (java.util.List)10 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 StringWriter (java.io.StringWriter)5 Enterprise (com.itrus.portal.db.Enterprise)4