Java Code Examples for org.codehaus.jackson.JsonToken#VALUE_NULL

The following examples show how to use org.codehaus.jackson.JsonToken#VALUE_NULL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveJsonStructReader.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
private Object parseMap(JsonParser parser, MapObjectInspector oi)
        throws IOException, SerDeException {
    if (parser.getCurrentToken() == JsonToken.VALUE_NULL) {
        parser.nextToken();
        return null;
    }

    Map<Object, Object> ret = new LinkedHashMap<>();

    if (parser.getCurrentToken() != JsonToken.START_OBJECT) {
        throw new SerDeException("struct expected");
    }

    if (!(oi.getMapKeyObjectInspector() instanceof PrimitiveObjectInspector)) {
        throw new SerDeException("map key must be a primitive");
    }
    PrimitiveObjectInspector keyOI = (PrimitiveObjectInspector) oi.getMapKeyObjectInspector();
    ObjectInspector valOI = oi.getMapValueObjectInspector();

    JsonToken currentToken = parser.nextToken();
    while (currentToken != null && currentToken != JsonToken.END_OBJECT) {

        if (currentToken != JsonToken.FIELD_NAME) {
            throw new SerDeException("unexpected token: " + currentToken);
        }

        Object key = parseMapKey(parser, keyOI);
        Object val = parseDispatcher(parser, valOI);
        ret.put(key, val);

        currentToken = parser.getCurrentToken();
    }
    if (currentToken != null) {
        parser.nextToken();
    }
    return ret;
}
 
Example 2
Source File: HiveJsonStructReader.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
private Object parseList(JsonParser parser, ListObjectInspector oi)
        throws JsonParseException, IOException, SerDeException {
    List<Object> ret = new ArrayList<>();

    if (parser.getCurrentToken() == JsonToken.VALUE_NULL) {
        parser.nextToken();
        return null;
    }

    if (parser.getCurrentToken() != JsonToken.START_ARRAY) {
        throw new SerDeException("array expected");
    }
    ObjectInspector eOI = oi.getListElementObjectInspector();
    JsonToken currentToken = parser.nextToken();
    try {
        while (currentToken != null && currentToken != JsonToken.END_ARRAY) {
            ret.add(parseDispatcher(parser, eOI));
            currentToken = parser.getCurrentToken();
        }
    } catch (Exception e) {
        throw new SerDeException("array: " + e.getMessage(), e);
    }

    currentToken = parser.nextToken();

    return ret;
}