Example usage for com.fasterxml.jackson.core JsonToken END_ARRAY

List of usage examples for com.fasterxml.jackson.core JsonToken END_ARRAY

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonToken END_ARRAY.

Prototype

JsonToken END_ARRAY

To view the source code for com.fasterxml.jackson.core JsonToken END_ARRAY.

Click Source Link

Document

END_ARRAY is returned when encountering ']' which signals ending of an Array value

Usage

From source file:org.apache.lucene.server.handlers.AddDocumentHandler.java

/** Parse one value for a field, which is either an
 *  object matching the type of the field, or a {boost:
 *  ..., value: ...}. *///from ww w  . j av  a2  s.  co  m
private static boolean parseOneValue(FieldDef fd, JsonParser p, Document doc) throws IOException {

    Object o = null;
    float boost = 1.0f;

    JsonToken token = p.nextToken();
    if (token == JsonToken.START_ARRAY) {
        if ("hierarchy".equals(fd.faceted) || fd.valueType == FieldDef.FieldValueType.LAT_LON) {
            o = getNativeValue(fd, token, p);
        } else {
            if (fd.multiValued == false) {
                fail(fd.name, "expected single value, not array, since this field is not multiValued");
            }
            while (true) {
                if (!parseOneValue(fd, p, doc)) {
                    break;
                }
            }
            return true;
        }
    } else {

        if (token == JsonToken.END_ARRAY) {
            assert fd.multiValued;
            return false;
        }

        if (fd.fieldType.indexOptions() != IndexOptions.NONE && token == JsonToken.START_OBJECT) {
            // Parse a {boost: X, value: Y}
            while (true) {
                token = p.nextToken();
                if (token == JsonToken.END_OBJECT) {
                    break;
                }
                assert token == JsonToken.FIELD_NAME;
                String key = p.getText();
                if (key.equals("boost")) {
                    token = p.nextToken();
                    if (token == JsonToken.VALUE_NUMBER_INT || token == JsonToken.VALUE_NUMBER_FLOAT) {
                        boost = p.getFloatValue();
                    } else {
                        fail(fd.name, "boost in inner object field value must have float or int value; got: "
                                + token);
                    }
                } else if (key.equals("value")) {
                    o = getNativeValue(fd, p.nextToken(), p);
                } else {
                    fail(fd.name, "unrecognized json key \"" + key
                            + "\" in inner object field value; must be boost or value");
                }
            }
            if (o == null) {
                fail(fd.name, "missing 'value' key");
            }
        } else {
            // Parse a native value:
            o = getNativeValue(fd, token, p);
        }
    }

    parseOneNativeValue(fd, doc, o, boost);
    return true;
}

From source file:org.h2gis.drivers.geojson.GeoJsonReaderDriver.java

/**
 * Parses the featureCollection/* ww  w.  jav a2  s  .com*/
 *
 * @param jp
 * @throws IOException
 * @throws SQLException
 */
private void parseFeatures(JsonParser jp) throws IOException, SQLException {
    jp.nextToken(); // FIELD_NAME features
    String firstParam = jp.getText();
    if (firstParam.equalsIgnoreCase(GeoJsonField.CRS)) {
        firstParam = skipCRS(jp);
    }
    if (firstParam.equalsIgnoreCase(GeoJsonField.FEATURES)) {
        jp.nextToken(); // START_ARRAY [
        JsonToken token = jp.nextToken(); // START_OBJECT {
        while (token != JsonToken.END_ARRAY) {
            jp.nextToken(); // FIELD_NAME type
            jp.nextToken(); // VALUE_STRING Feature
            String geomType = jp.getText();
            if (geomType.equalsIgnoreCase(GeoJsonField.FEATURE)) {
                if (progress.isCanceled()) {
                    throw new SQLException("Canceled by user");
                }
                parseFeature(jp);
                token = jp.nextToken(); //START_OBJECT new feature                    
                featureCounter++;
                if (nodeCountProgress++ % readFileSizeEachNode == 0) {
                    // Update Progress
                    try {
                        progress.setStep((int) (((double) fc.position() / fileSize) * 100));
                    } catch (IOException ex) {
                        // Ignore
                    }
                }
            } else {
                throw new SQLException("Malformed GeoJSON file. Expected 'Feature', found '" + geomType + "'");
            }
        }
        //LOOP END_ARRAY ]
    } else {
        throw new SQLException("Malformed GeoJSON file. Expected 'features', found '" + firstParam + "'");
    }
}

From source file:com.evolveum.midpoint.prism.lex.json.AbstractJsonLexicalProcessor.java

private ListXNode parseToList(JsonParsingContext ctx, IterativeParsingContext ipc)
        throws SchemaException, IOException {
    Validate.notNull(ctx.parser.currentToken());

    ListXNode list = new ListXNode();
    Object tid = ctx.parser.getTypeId();
    if (tid != null) {
        list.setTypeQName(tagToTypeName(tid, ctx));
    }/*w w  w  .j  av a 2s.co  m*/
    if (ipc != null) {
        ipc.dataSent = true;
    }
    for (;;) {
        JsonToken token = ctx.parser.nextToken();
        if (token == null) {
            ctx.prismParsingContext.warnOrThrow(LOGGER,
                    "Unexpected end of data while parsing a list structure at " + getPositionSuffix(ctx));
            return list;
        } else if (token == JsonToken.END_ARRAY) {
            return list;
        } else {
            if (ipc != null) {
                JsonParsingContext childCtx = ctx.createChildContext();
                XNode value = parseValue(childCtx, null);
                List<RootXNode> childRoots = valueToRootList(value, ipc.defaultNamespace, childCtx);
                for (RootXNode childRoot : childRoots) {
                    if (!ipc.handler.handleData(childRoot)) {
                        ipc.abortProcessing = true;
                        assert list.isEmpty();
                        return list;
                    }
                }
            } else {
                list.add(parseValue(ctx, null));
            }
        }
    }
}

From source file:com.github.heuermh.personalgenome.client.converter.JacksonPersonalGenomeConverter.java

@Override
public List<Risk> parseRisks(final InputStream inputStream) {
    checkNotNull(inputStream);/*from w  ww.  j  av a  2  s  .  c o  m*/
    JsonParser parser = null;
    try {
        parser = jsonFactory.createParser(inputStream);
        parser.nextToken();

        String id = null;
        String reportId = null;
        String description = null;
        double risk = 0.0d;
        double populationRisk = 0.0d;
        List<Risk> risks = new ArrayList<Risk>();
        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String field = parser.getCurrentName();
            parser.nextToken();

            if ("id".equals(field)) {
                id = parser.getText();
            } else if ("risks".equals(field)) {
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    while (parser.nextToken() != JsonToken.END_OBJECT) {
                        String riskField = parser.getCurrentName();
                        parser.nextToken();

                        if ("report_id".equals(riskField)) {
                            reportId = parser.getText();
                        } else if ("description".equals(riskField)) {
                            description = parser.getText();
                        } else if ("risk".equals(riskField)) {
                            risk = Double.parseDouble(parser.getText());
                        } else if ("population_risk".equals(riskField)) {
                            populationRisk = Double.parseDouble(parser.getText());
                        }
                    }
                    risks.add(new Risk(id, reportId, description, risk, populationRisk));
                    reportId = null;
                    description = null;
                    risk = 0.0d;
                    populationRisk = 0.0d;
                }
            }
        }
        return risks;
    } catch (IOException e) {
        logger.warn("could not parse risks", e);
    } finally {
        try {
            inputStream.close();
        } catch (Exception e) {
            // ignored
        }
        try {
            parser.close();
        } catch (Exception e) {
            // ignored
        }
    }
    return null;
}

From source file:org.h2gis.drivers.geojson.GeoJsonReaderDriver.java

/**
 * Parses an array of positions defined as:
 *
 * { "type": "MultiLineString", "coordinates": [ [ [100.0, 0.0], [101.0,
 * 1.0] ], [ [102.0, 2.0], [103.0, 3.0] ] ] }
 *
 * @param jsParser//from w  w  w  . j ava2 s . com
 * @return MultiLineString
 */
private MultiLineString parseMultiLinestring(JsonParser jp) throws IOException, SQLException {
    jp.nextToken(); // FIELD_NAME coordinates        
    String coordinatesField = jp.getText();
    if (coordinatesField.equalsIgnoreCase(GeoJsonField.COORDINATES)) {
        ArrayList<LineString> lineStrings = new ArrayList<LineString>();
        jp.nextToken();//START_ARRAY [ coordinates
        jp.nextToken(); // START_ARRAY [ coordinates line
        while (jp.getCurrentToken() != JsonToken.END_ARRAY) {
            lineStrings.add(GF.createLineString(parseCoordinates(jp)));
            jp.nextToken();
        }
        MultiLineString line = GF
                .createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()]));
        jp.nextToken();//END_OBJECT } geometry
        return line;
    } else {
        throw new SQLException(
                "Malformed GeoJSON file. Expected 'coordinates', found '" + coordinatesField + "'");
    }

}

From source file:com.adobe.communities.ugc.migration.importer.UGCImportHelper.java

protected void extractTopic(final JsonParser jsonParser, final Resource resource,
        final ResourceResolver resolver, final CommentOperations operations)
        throws IOException, ServletException {
    if (jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) {
        return; // replies could just be an empty object (i.e. "ugc:replies":{} ) in which case, do nothing
    }/*from   w  w  w. j av  a2  s .  co  m*/
    final Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("social:key", jsonParser.getCurrentName());
    Resource post = null;
    jsonParser.nextToken();
    if (jsonParser.getCurrentToken().equals(JsonToken.START_OBJECT)) {
        jsonParser.nextToken();
        String author = null;
        List<DataSource> attachments = new ArrayList<DataSource>();
        while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) {
            final String label = jsonParser.getCurrentName();
            JsonToken token = jsonParser.nextToken();
            if (jsonParser.getCurrentToken().isScalarValue()) {

                // either a string, boolean, or long value
                if (token.isNumeric()) {
                    properties.put(label, jsonParser.getValueAsLong());
                } else {
                    final String value = jsonParser.getValueAsString();
                    if (value.equals("true") || value.equals("false")) {
                        properties.put(label, jsonParser.getValueAsBoolean());
                    } else {
                        final String decodedValue = URLDecoder.decode(value, "UTF-8");
                        if (label.equals("language")) {
                            properties.put("mtlanguage", decodedValue);
                        } else {
                            properties.put(label, decodedValue);
                            if (label.equals("userIdentifier")) {
                                author = decodedValue;
                            } else if (label.equals("jcr:description")) {
                                properties.put("message", decodedValue);
                            }
                        }
                    }
                }
            } else if (label.equals(ContentTypeDefinitions.LABEL_ATTACHMENTS)) {
                attachments = getAttachments(jsonParser);
            } else if (label.equals(ContentTypeDefinitions.LABEL_REPLIES)
                    || label.equals(ContentTypeDefinitions.LABEL_TALLY)
                    || label.equals(ContentTypeDefinitions.LABEL_TRANSLATION)
                    || label.equals(ContentTypeDefinitions.LABEL_SUBNODES)) {
                // replies and sub-nodes ALWAYS come after all other properties and attachments have been listed,
                // so we can create the post now if we haven't already, and then dive in
                if (post == null) {
                    try {
                        post = createPost(resource, author, properties, attachments,
                                resolver.adaptTo(Session.class), operations);
                        resProvider = SocialResourceUtils.getSocialResource(post).getResourceProvider();
                    } catch (Exception e) {
                        throw new ServletException(e.getMessage(), e);
                    }
                }
                if (label.equals(ContentTypeDefinitions.LABEL_REPLIES)) {
                    if (token.equals(JsonToken.START_OBJECT)) {
                        jsonParser.nextToken();
                        while (!token.equals(JsonToken.END_OBJECT)) {
                            extractTopic(jsonParser, post, resolver, operations);
                            token = jsonParser.nextToken();
                        }
                    } else {
                        throw new IOException("Expected an object for the subnodes");
                    }
                } else if (label.equals(ContentTypeDefinitions.LABEL_SUBNODES)) {
                    if (token.equals(JsonToken.START_OBJECT)) {
                        token = jsonParser.nextToken();
                        try {
                            while (!token.equals(JsonToken.END_OBJECT)) {
                                final String subnodeType = jsonParser.getCurrentName();
                                token = jsonParser.nextToken();
                                if (token.equals(JsonToken.START_OBJECT)) {
                                    jsonParser.skipChildren();
                                    token = jsonParser.nextToken();
                                }
                            }
                        } catch (final IOException e) {
                            throw new IOException("unable to skip child of sub-nodes", e);
                        }
                    } else {
                        final String field = jsonParser.getValueAsString();
                        throw new IOException("Expected an object for the subnodes. Instead: " + field);
                    }
                } else if (label.equals(ContentTypeDefinitions.LABEL_TALLY)) {
                    UGCImportHelper.extractTally(post, jsonParser, resProvider, tallyOperationsService);
                } else if (label.equals(ContentTypeDefinitions.LABEL_TRANSLATION)) {
                    importTranslation(jsonParser, post);
                    resProvider.commit(post.getResourceResolver());
                }

            } else if (jsonParser.getCurrentToken().equals(JsonToken.START_OBJECT)) {
                properties.put(label, UGCImportHelper.extractSubmap(jsonParser));
            } else if (jsonParser.getCurrentToken().equals(JsonToken.START_ARRAY)) {
                jsonParser.nextToken(); // skip the START_ARRAY token
                if (label.equals(ContentTypeDefinitions.LABEL_TIMESTAMP_FIELDS)) {
                    while (!jsonParser.getCurrentToken().equals(JsonToken.END_ARRAY)) {
                        final String timestampLabel = jsonParser.getValueAsString();
                        if (properties.containsKey(timestampLabel)
                                && properties.get(timestampLabel) instanceof Long) {
                            final Calendar calendar = new GregorianCalendar();
                            calendar.setTimeInMillis((Long) properties.get(timestampLabel));
                            properties.put(timestampLabel, calendar.getTime());
                        }
                        jsonParser.nextToken();
                    }
                } else {
                    final List<String> subArray = new ArrayList<String>();
                    while (!jsonParser.getCurrentToken().equals(JsonToken.END_ARRAY)) {
                        subArray.add(jsonParser.getValueAsString());
                        jsonParser.nextToken();
                    }
                    String[] strings = new String[subArray.size()];
                    for (int i = 0; i < subArray.size(); i++) {
                        strings[i] = subArray.get(i);
                    }
                    properties.put(label, strings);
                }
            }
            jsonParser.nextToken();
        }
        if (post == null) {
            try {
                post = createPost(resource, author, properties, attachments, resolver.adaptTo(Session.class),
                        operations);
                if (null == resProvider) {
                    resProvider = SocialResourceUtils.getSocialResource(post).getResourceProvider();
                }
                // resProvider.commit(resolver);
            } catch (Exception e) {
                throw new ServletException(e.getMessage(), e);
            }
        }
    } else {
        throw new IOException("Improperly formed JSON - expected an OBJECT_START token, but got "
                + jsonParser.getCurrentToken().toString());
    }
}

From source file:com.github.heuermh.personalgenome.client.converter.JacksonPersonalGenomeConverter.java

@Override
public List<Carrier> parseCarriers(final InputStream inputStream) {
    checkNotNull(inputStream);//  w ww . j  ava2s . com
    JsonParser parser = null;
    try {
        parser = jsonFactory.createParser(inputStream);
        parser.nextToken();

        String id = null;
        String reportId = null;
        String description = null;
        int mutations = 0;
        List<Carrier> carriers = new ArrayList<Carrier>();
        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String field = parser.getCurrentName();
            parser.nextToken();

            if ("id".equals(field)) {
                id = parser.getText();
            } else if ("carriers".equals(field)) {
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    while (parser.nextToken() != JsonToken.END_OBJECT) {
                        String carrierField = parser.getCurrentName();
                        parser.nextToken();

                        if ("report_id".equals(carrierField)) {
                            reportId = parser.getText();
                        } else if ("description".equals(carrierField)) {
                            description = parser.getText();
                        } else if ("mutations".equals(carrierField)) {
                            mutations = Integer.parseInt(parser.getText());
                        }
                    }
                    carriers.add(new Carrier(id, reportId, description, mutations));
                    reportId = null;
                    description = null;
                    mutations = 0;
                }
            }
        }
        return carriers;
    } catch (IOException e) {
        logger.warn("could not parse carriers", e);
    } finally {
        try {
            inputStream.close();
        } catch (Exception e) {
            // ignored
        }
        try {
            parser.close();
        } catch (Exception e) {
            // ignored
        }
    }
    return null;
}

From source file:org.h2gis.drivers.geojson.GeoJsonReaderDriver.java

/**
 * Coordinates of a Polygon are an array of LinearRing coordinate arrays.
 * The first element in the array represents the exterior ring. Any
 * subsequent elements represent interior rings (or holes).
 *
 * Syntax:/* w w w.  j  a v a 2  s  .  c om*/
 *
 * No holes:
 *
 * { "type": "Polygon", "coordinates": [ [ [100.0, 0.0], [101.0, 0.0],
 * [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ] }
 *
 * With holes:
 *
 * { "type": "Polygon", "coordinates": [ [ [100.0, 0.0], [101.0, 0.0],
 * [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ], [ [100.2, 0.2], [100.8, 0.2],
 * [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] ] }
 *
 *
 *
 * @param jp
 * @return Polygon
 */
private Polygon parsePolygon(JsonParser jp) throws IOException, SQLException {
    jp.nextToken(); // FIELD_NAME coordinates        
    String coordinatesField = jp.getText();
    if (coordinatesField.equalsIgnoreCase(GeoJsonField.COORDINATES)) {
        jp.nextToken(); // START_ARRAY [ coordinates
        jp.nextToken(); //Start the RING
        int linesIndex = 0;
        LinearRing linearRing = null;
        ArrayList<LinearRing> holes = new ArrayList<LinearRing>();
        while (jp.getCurrentToken() != JsonToken.END_ARRAY) {
            if (linesIndex == 0) {
                linearRing = GF.createLinearRing(parseCoordinates(jp));
            } else {
                holes.add(GF.createLinearRing(parseCoordinates(jp)));
            }
            jp.nextToken();//END RING
            linesIndex++;
        }
        if (linesIndex > 1) {
            jp.nextToken();//END_OBJECT } geometry
            return GF.createPolygon(linearRing, holes.toArray(new LinearRing[holes.size()]));
        } else {
            jp.nextToken();//END_OBJECT } geometry
            return GF.createPolygon(linearRing, null);
        }
    } else {
        throw new SQLException(
                "Malformed GeoJSON file. Expected 'coordinates', found '" + coordinatesField + "'");
    }
}

From source file:com.ntsync.shared.RawContact.java

/**
 * Creates and returns an instance of the RawContact from encrypted data
 * /*w  w w. j ava  2  s  .  co m*/
 * */
public static RawContact valueOf(String rowId, Map<Byte, ByteBuffer> values, Key privateKey)
        throws InvalidKeyException {
    try {
        String serverContactId = null;
        long rawContactId = -1;
        if (values.containsKey(ContactConstants.SERVERROW_ID)) {
            serverContactId = readRawString(values.get(ContactConstants.SERVERROW_ID));
        }
        String lastModStr = readRawString(values.get(ContactConstants.MODIFIED));
        Date lastModified = null;
        if (lastModStr != null) {
            lastModified = new Date(Long.parseLong(lastModStr));
        }

        if (serverContactId == null || !serverContactId.equals(rowId)) {
            // If ServerContactId is different, then rowId is the clientId
            rawContactId = Long.parseLong(rowId);
        }

        if (serverContactId == null && rawContactId < 0) {
            throw new IllegalArgumentException("Missing RowId in data");
        }

        AEADBlockCipher cipher = CryptoHelper.getCipher();
        final boolean deleted = values.containsKey(ContactConstants.DELETED);

        final String textData = CryptoHelper.decodeStringValue(ContactConstants.TEXTDATA, values, cipher,
                privateKey);

        if (textData == null && !deleted) {
            LOG.error("No textdata found for row with Id:" + rowId);
            return null;
        }

        String fullName = null;
        String firstName = null;
        String lastName = null;
        String middleName = null;
        String prefixName = null;
        String suffixName = null;
        String phonecticFirst = null;
        String phonecticMiddle = null;
        String phonecticLast = null;
        List<String> groupSourceIds = null;
        String note = null;
        List<ListRawData<PhoneType>> phones = null;
        List<ListRawData<EmailType>> emails = null;
        List<ListRawData<WebsiteType>> websites = null;
        List<ListRawData<EventType>> events = null;
        List<ListRawData<RelationType>> relations = null;
        List<ListRawData<SipAddressType>> sipaddresses = null;
        List<ListRawData<NicknameType>> nicknames = null;
        List<RawAddressData> addresses = null;
        List<RawImData> imAddresses = null;
        RawOrganizationData organization = null;
        boolean photoSuperPrimary = false;
        boolean starred = false;
        String customRingtone = null;
        boolean sendToVoiceMail = false;

        if (!SyncDataHelper.isEmpty(textData)) {
            JsonFactory fac = new JsonFactory();
            JsonParser jp = fac.createParser(textData);
            jp.nextToken();
            while (jp.nextToken() != JsonToken.END_OBJECT) {
                String fieldname = jp.getCurrentName();
                // move to value, or START_OBJECT/START_ARRAY
                jp.nextToken();
                if (ContactConstants.STRUCTUREDNAME.equals(fieldname)) {
                    while (jp.nextToken() != JsonToken.END_OBJECT) {
                        String namefield = jp.getCurrentName();
                        // move to value
                        if (jp.nextToken() == null) {
                            throw new JsonParseException("Invalid JSON-Structure. End of Object missing.",
                                    jp.getCurrentLocation());
                        }
                        if (ContactConstants.DISPLAY_NAME.equals(namefield)) {
                            fullName = jp.getValueAsString();
                        } else if (ContactConstants.FAMILY_NAME.equals(namefield)) {
                            lastName = jp.getValueAsString();
                        } else if (ContactConstants.GIVEN_NAME.equals(namefield)) {
                            firstName = jp.getValueAsString();
                        } else if (ContactConstants.MIDDLE_NAME.equals(namefield)) {
                            middleName = jp.getValueAsString();
                        } else if (ContactConstants.SUFFIX_NAME.equals(namefield)) {
                            suffixName = jp.getValueAsString();
                        } else if (ContactConstants.PREFIX_NAME.equals(namefield)) {
                            prefixName = jp.getValueAsString();
                        } else if (ContactConstants.PHONETIC_FAMILY.equals(namefield)) {
                            phonecticLast = jp.getValueAsString();
                        } else if (ContactConstants.PHONETIC_GIVEN.equals(namefield)) {
                            phonecticFirst = jp.getValueAsString();
                        } else if (ContactConstants.PHONETIC_MIDDLE.equals(namefield)) {
                            phonecticMiddle = jp.getValueAsString();
                        } else {
                            LOG.error("Unrecognized structurednamefield for row with Id:" + rowId
                                    + " Fieldname:" + fieldname);
                            break;
                        }
                    }
                } else if (ContactConstants.STRUCTUREDPOSTAL.equals(fieldname)) {
                    addresses = readAddressList(rowId, addresses, jp);
                } else if (ContactConstants.PHONE.equals(fieldname)) {
                    phones = readJsonList(rowId, phones, jp, fieldname, PhoneType.TYPE_OTHER, PhoneType.class);
                } else if (ContactConstants.EMAIL.equals(fieldname)) {
                    emails = readJsonList(rowId, emails, jp, fieldname, EmailType.TYPE_OTHER, EmailType.class);
                } else if (ContactConstants.WEBSITE.equals(fieldname)) {
                    websites = readJsonList(rowId, websites, jp, fieldname, WebsiteType.TYPE_OTHER,
                            WebsiteType.class);
                } else if (ContactConstants.EVENT.equals(fieldname)) {
                    events = readJsonList(rowId, events, jp, fieldname, EventType.TYPE_OTHER, EventType.class);
                } else if (ContactConstants.RELATION.equals(fieldname)) {
                    relations = readJsonList(rowId, relations, jp, fieldname, RelationType.TYPE_CUSTOM,
                            RelationType.class);
                } else if (ContactConstants.SIPADDRESS.equals(fieldname)) {
                    sipaddresses = readJsonList(rowId, sipaddresses, jp, fieldname, SipAddressType.TYPE_OTHER,
                            SipAddressType.class);
                } else if (ContactConstants.NICKNAME.equals(fieldname)) {
                    nicknames = readJsonList(rowId, nicknames, jp, fieldname, NicknameType.TYPE_DEFAULT,
                            NicknameType.class);
                } else if (ContactConstants.IM.equals(fieldname)) {
                    imAddresses = readImList(rowId, imAddresses, jp);
                } else if (ContactConstants.NOTE.equals(fieldname)) {
                    note = jp.getValueAsString();
                } else if (ContactConstants.GROUPMEMBERSHIP.equals(fieldname)) {
                    while (jp.nextToken() != JsonToken.END_ARRAY) {
                        String groupSourceId = jp.getValueAsString();
                        if (groupSourceIds == null) {
                            groupSourceIds = new ArrayList<String>();
                        }
                        groupSourceIds.add(groupSourceId);
                    }
                } else if (ContactConstants.ORGANIZATION.equals(fieldname)) {
                    organization = readOrg(rowId, jp);
                } else if (ContactConstants.PHOTO_SUPERPRIMARY.equals(fieldname)) {
                    photoSuperPrimary = jp.getValueAsBoolean();
                } else if (ContactConstants.STARRED.equals(fieldname)) {
                    starred = jp.getValueAsBoolean();
                } else if (ContactConstants.SEND_TO_VOICE_MAIL.equals(fieldname)) {
                    sendToVoiceMail = jp.getValueAsBoolean();
                } else if (ContactConstants.DROID_CUSTOM_RINGTONE.equals(fieldname)) {
                    customRingtone = jp.getValueAsString();
                } else {
                    LOG.error("Unrecognized field for row with Id:" + rowId + " Fieldname:" + fieldname);
                }
            }
            jp.close();
        }

        final byte[] photo = CryptoHelper.decodeValue(ContactConstants.PHOTO, values, cipher, privateKey);

        return new RawContact(fullName, firstName, lastName, middleName, prefixName, suffixName, phonecticFirst,
                phonecticMiddle, phonecticLast, phones, emails, websites, addresses, events, relations,
                sipaddresses, nicknames, imAddresses, note, organization, photo, photoSuperPrimary,
                groupSourceIds, null, starred, customRingtone, sendToVoiceMail, lastModified, deleted,
                serverContactId, rawContactId, false, -1);
    } catch (InvalidCipherTextException ex) {
        throw new InvalidKeyException("Invalid key detected.", ex);
    } catch (final IOException ex) {
        LOG.info("Error parsing contact data. Reason:" + ex.toString(), ex);
    } catch (IllegalArgumentException ex) {
        LOG.warn("Error parsing contact data. Reason:" + ex.toString(), ex);
    }

    return null;
}