<commit_before>package by.istin.android.xcore.gson;

import android.content.ContentValues;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.List;

import by.istin.android.xcore.annotations.JsonEntityConverter;
import by.istin.android.xcore.annotations.JsonSubJSONObject;
import by.istin.android.xcore.annotations.dbBoolean;
import by.istin.android.xcore.annotations.dbByte;
import by.istin.android.xcore.annotations.dbDouble;
import by.istin.android.xcore.annotations.dbEntities;
import by.istin.android.xcore.annotations.dbEntity;
import by.istin.android.xcore.annotations.dbInteger;
import by.istin.android.xcore.annotations.dbLong;
import by.istin.android.xcore.annotations.dbString;
import by.istin.android.xcore.utils.ReflectUtils;

public abstract class AbstractValuesAdapter<T> implements JsonDeserializer<T> {

    public static final int UNKNOWN_POSITION = -1;


    private Class<?> mContentValuesEntityClazz;

    private List<Field> mEntityKeys;

    public Class<?> getContentValuesEntityClazz() {
        return mContentValuesEntityClazz;
    }

    public AbstractValuesAdapter(Class<?> contentValuesEntityClazz) {
        this.mContentValuesEntityClazz = contentValuesEntityClazz;
    }

    @Override
    public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        return deserializeContentValues(null, UNKNOWN_POSITION, jsonElement, type, jsonDeserializationContext);
    }

    protected T deserializeContentValues(T parent, int position, JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
        if (mEntityKeys == null) {
            mEntityKeys = ReflectUtils.getEntityKeys(mContentValuesEntityClazz);
        }
        ContentValues contentValues = new ContentValues();
        if (mEntityKeys == null) {
            return proceed(parent, position, contentValues);
        }
        if (isCustomConverter(contentValues, parent, jsonElement, type, jsonDeserializationContext)) {
            return proceed(parent, position, contentValues);
        }
        if (jsonElement.isJsonPrimitive()) {
            return null;
        }
        JsonObject jsonObject = (JsonObject) jsonElement;<commit_msg>fixed issue when instead of jsonobject we have json array in the feed<commit_after>package by.istin.android.xcore.gson;

import android.content.ContentValues;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.List;

import by.istin.android.xcore.annotations.JsonEntityConverter;
import by.istin.android.xcore.annotations.JsonSubJSONObject;
import by.istin.android.xcore.annotations.dbBoolean;
import by.istin.android.xcore.annotations.dbByte;
import by.istin.android.xcore.annotations.dbDouble;
import by.istin.android.xcore.annotations.dbEntities;
import by.istin.android.xcore.annotations.dbEntity;
import by.istin.android.xcore.annotations.dbInteger;
import by.istin.android.xcore.annotations.dbLong;
import by.istin.android.xcore.annotations.dbString;
import by.istin.android.xcore.utils.ReflectUtils;

public abstract class AbstractValuesAdapter<T> implements JsonDeserializer<T> {

    public static final int UNKNOWN_POSITION = -1;


    private Class<?> mContentValuesEntityClazz;

    private List<Field> mEntityKeys;

    public Class<?> getContentValuesEntityClazz() {
        return mContentValuesEntityClazz;
    }

    public AbstractValuesAdapter(Class<?> contentValuesEntityClazz) {
        this.mContentValuesEntityClazz = contentValuesEntityClazz;
    }

    @Override
    public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        return deserializeContentValues(null, UNKNOWN_POSITION, jsonElement, type, jsonDeserializationContext);
    }

    protected T deserializeContentValues(T parent, int position, JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
        if (mEntityKeys == null) {
            mEntityKeys = ReflectUtils.getEntityKeys(mContentValuesEntityClazz);
        }
        ContentValues contentValues = new ContentValues();
        if (mEntityKeys == null) {
            return proceed(parent, position, contentValues);
        }
        if (isCustomConverter(contentValues, parent, jsonElement, type, jsonDeserializationContext)) {
            return proceed(parent, position, contentValues);
        }
        if (jsonElement.isJsonPrimitive()) {
            return null;
        }
        if (jsonElement.isJsonArray()) {
            return null;
        }
        JsonObject jsonObject = (JsonObject) jsonElement;
{'fraction_non_alphanumeric': 0.08626560726447219, 'fraction_numerical': 0.00037835792659856227, 'mean_word_length': 4.4281314168377826, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2375308', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1468, 'n_words': 289}