Search in sources :

Example 1 with ParseException

use of org.apache.storm.hdfs.spout.ParseException in project streamline by hortonworks.

the class JsonFileReader method next.

// returns null when EOF is reached
public List<Object> next() throws IOException, ParseException {
    List<Object> lineTuple = super.next();
    if (lineTuple == null)
        return null;
    String jsonLine = (String) lineTuple.get(0);
    if (jsonLine.trim().isEmpty())
        return next();
    try {
        // 1- convert Json to Map<>
        HashMap<String, Object> jsonMap = new ObjectMapper().readValue(jsonLine, HashMap.class);
        // 2- make StreamlineEvent from map
        StreamlineEventImpl slEvent = StreamlineEventImpl.builder().putAll(jsonMap).dataSourceId("HdfsSpout").build();
        // 3- create tuple from StreamlineEvent
        return Collections.singletonList(slEvent);
    } catch (JsonProcessingException e) {
        throw new ParseException("Json parsing error at location : " + getFileOffset().toString(), e);
    }
}
Also used : ParseException(org.apache.storm.hdfs.spout.ParseException) StreamlineEventImpl(com.hortonworks.streamline.streams.common.StreamlineEventImpl) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)1 ParseException (org.apache.storm.hdfs.spout.ParseException)1