/** * Constructor resource responses. * * @param data provides the batch response data. * @param keyType provides the class identifying the key type. * <ul> * <li>For collection resources must be a primitive or a typeref to a primitive.</li> * <li>For an association resources must be {@link CompoundKey} and keyParts must contain an entry for each association key field.</li> * <li>For complex resources must be {@link ComplexResourceKey}, keyKeyClass must contain the * key's record template class and if the resource has a key params their record template type keyParamsClass must be provided.</li> * @param valueType provides the entity type of the collection. * @param keyParts provides a map for association keys of each key name to {@link CompoundKey.TypeInfo}, for non-association resources must be an empty map. * @param complexKeyType provides the type of the key for complex key resources, otherwise null. */ public BatchKVResponse(DataMap data, TypeSpec<K> keyType, TypeSpec<V> valueType, Map<String, CompoundKey.TypeInfo> keyParts, ComplexKeySpec<?, ?> complexKeyType, ProtocolVersion version) { super(data, null); _valueClass = valueType.getType(); deserializeData(keyType, keyParts, complexKeyType, version); }
protected void deserializeData(DataMap data, TypeSpec<K> keyType, Map<String, CompoundKey.TypeInfo> keyParts, ComplexKeySpec<?, ?> complexKeyType, ProtocolVersion version) { final DataMap resultsRaw = data.getDataMap(RESULTS); if (resultsRaw == null) { _results = new ParamlessKeyHashMap<V>(complexKeyType); } else { _results = new ParamlessKeyHashMap<V>( CollectionUtils.getMapInitialCapacity(resultsRaw.size(), 0.75f), 0.75f, complexKeyType); for (Map.Entry<String, Object> entry : resultsRaw.entrySet()) { @SuppressWarnings("unchecked") final K key = (K) ResponseUtils.convertKey(entry.getKey(), keyType, keyParts, complexKeyType, version); final V value = deserializeValue(entry.getValue()); _results.put(key, value); } } final DataMap errorsRaw = data.getDataMap(ERRORS); if (errorsRaw == null) { _errors = new ParamlessKeyHashMap<ErrorResponse>(complexKeyType); } else {
CheckedUtil.putWithoutChecking(convertedData, ERRORS, inputErrors); super.deserializeData(convertedData, keyType, keyParts, complexKeyType, version);