
com.yahoo.document.json.readers.ArrayReader Maven / Gradle / Ivy
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.json.readers;
import com.fasterxml.jackson.core.JsonToken;
import com.google.common.base.Preconditions;
import com.yahoo.document.DataType;
import com.yahoo.document.datatypes.CollectionFieldValue;
import com.yahoo.document.datatypes.FieldValue;
import com.yahoo.document.json.TokenBuffer;
import java.util.List;
import static com.yahoo.document.json.readers.JsonParserHelpers.expectArrayStart;
import static com.yahoo.document.json.readers.SingleValueReader.readSingleValue;
public class ArrayReader {
public static void fillArrayUpdate(TokenBuffer buffer, int initNesting, DataType valueType, List arrayContents) {
while (buffer.nesting() >= initNesting) {
Preconditions.checkArgument(buffer.currentToken() != JsonToken.VALUE_NULL, "Illegal null value for array entry");
arrayContents.add(readSingleValue(buffer, valueType));
buffer.next();
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void fillArray(TokenBuffer buffer, CollectionFieldValue parent, DataType valueType) {
int initNesting = buffer.nesting();
expectArrayStart(buffer.currentToken());
buffer.next();
while (buffer.nesting() >= initNesting) {
Preconditions.checkArgument(buffer.currentToken() != JsonToken.VALUE_NULL, "Illegal null value for array entry");
parent.add(readSingleValue(buffer, valueType));
buffer.next();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy