Search in sources :

Example 1 with JsonReaderException

use of com.yahoo.document.json.JsonReaderException in project vespa by vespa-engine.

the class StructReader method fillStruct.

public static void fillStruct(TokenBuffer buffer, StructuredFieldValue parent) {
    // do note the order of initializing initNesting and token is relevant for empty docs
    int initNesting = buffer.nesting();
    buffer.next();
    while (buffer.nesting() >= initNesting) {
        Field f = getField(buffer, parent);
        try {
            FieldValue v = readSingleValue(buffer, f.getDataType());
            parent.setFieldValue(f, v);
            buffer.next();
        } catch (IllegalArgumentException e) {
            throw new JsonReaderException(f, e);
        }
    }
}
Also used : Field(com.yahoo.document.Field) JsonReaderException(com.yahoo.document.json.JsonReaderException) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 2 with JsonReaderException

use of com.yahoo.document.json.JsonReaderException in project vespa by vespa-engine.

the class VespaJsonDocumentReader method createDocumentOperation.

public DocumentOperation createDocumentOperation(DocumentType documentType, DocumentParseInfo documentParseInfo) {
    final DocumentOperation documentOperation;
    try {
        switch(documentParseInfo.operationType) {
            case PUT:
                documentOperation = new DocumentPut(new Document(documentType, documentParseInfo.documentId));
                readPut(documentParseInfo.fieldsBuffer, (DocumentPut) documentOperation);
                verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
                break;
            case REMOVE:
                documentOperation = new DocumentRemove(documentParseInfo.documentId);
                break;
            case UPDATE:
                documentOperation = new DocumentUpdate(documentType, documentParseInfo.documentId);
                readUpdate(documentParseInfo.fieldsBuffer, (DocumentUpdate) documentOperation);
                verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
                break;
            default:
                throw new IllegalStateException("Implementation out of sync with itself. This is a bug.");
        }
    } catch (JsonReaderException e) {
        throw JsonReaderException.addDocId(e, documentParseInfo.documentId);
    }
    if (documentParseInfo.create.isPresent()) {
        if (!(documentOperation instanceof DocumentUpdate)) {
            throw new RuntimeException("Could not set create flag on non update operation.");
        }
        DocumentUpdate update = (DocumentUpdate) documentOperation;
        update.setCreateIfNonExistent(documentParseInfo.create.get());
    }
    return documentOperation;
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentUpdate(com.yahoo.document.DocumentUpdate) JsonReaderException(com.yahoo.document.json.JsonReaderException) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Aggregations

JsonReaderException (com.yahoo.document.json.JsonReaderException)2 Document (com.yahoo.document.Document)1 DocumentOperation (com.yahoo.document.DocumentOperation)1 DocumentPut (com.yahoo.document.DocumentPut)1 DocumentRemove (com.yahoo.document.DocumentRemove)1 DocumentUpdate (com.yahoo.document.DocumentUpdate)1 Field (com.yahoo.document.Field)1 FieldValue (com.yahoo.document.datatypes.FieldValue)1 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)1