public <K, V, D> ViewResponse<K, V, D> deserialize( @Nonnull JacksonSerializer<? super K> keySerializer, @Nonnull JacksonSerializer<? super V> valueSerializer, @Nullable JacksonSerializer<? extends D> documentSerializer, @Nonnull InputStream in ) throws IOException, InvalidTypeException {
JsonFactory jsonFactory = JacksonSupport.getJsonFactory();
JsonParser parser = jsonFactory.createJsonParser( in );
JacksonParserWrapper parserWrapper = new JacksonParserWrapper( parser );
parserWrapper.nextToken( JsonToken.START_OBJECT );
parserWrapper.nextToken( JsonToken.FIELD_NAME );
//If reduced, no total rows and no offset are availlable!
String fieldName = parser.getText();
int totalRows = -1;
int offset = -1;
while ( !fieldName.equals( PROPERTY_ROWS ) ) {
if ( fieldName.equals( PROPERTY_TOTAL_ROWS ) ) {
parserWrapper.nextToken( JsonToken.VALUE_NUMBER_INT );
totalRows = parser.getIntValue();
}
if ( fieldName.equals( PROPERTY_OFFSET ) ) {
parserWrapper.nextToken( JsonToken.VALUE_NUMBER_INT );
offset = parser.getIntValue();
}
parserWrapper.nextToken( JsonToken.FIELD_NAME );
fieldName = parser.getText();
}
//Now the rows...
parserWrapper.nextToken( JsonToken.START_ARRAY );
List<Row<K, V, D>> deserialized = new ArrayList<>();
while ( parser.nextToken() != JsonToken.END_ARRAY ) {
Row<K, V, D> deserializedRow = rowSerializer.deserialize( keySerializer, valueSerializer, documentSerializer, parser );
deserialized.add( deserializedRow );