Example usage for java.lang.reflect Field setBoolean

List of usage examples for java.lang.reflect Field setBoolean

Introduction

In this page you can find the example usage for java.lang.reflect Field setBoolean.

Prototype

@CallerSensitive
@ForceInline 
public void setBoolean(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException 

Source Link

Document

Sets the value of a field as a boolean on the specified object.

Usage

From source file:uk.org.openseizuredetector.MainActivity.java

/** Called when the activity is first created. */
@Override/* w ww . jav a  2s  .c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialise the User Interface
    setContentView(R.layout.main);

    /* Force display of overflow menu - from stackoverflow
     * "how to force use of..."
     */
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        Log.v(TAG, "menubar fiddle exception: " + e.toString());
    }

    // start timer to refresh user interface every second.
    Timer uiTimer = new Timer();
    uiTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            updateServerStatus();
        }
    }, 0, 1000);

}

From source file:com.vinexs.eeb.BaseActivity.java

/**
 * <p>This hack used to add overflow menu button if device has physical menu button.
 * Phones with a physical menu button don't have an overflow menu in the ActionBar. </p>
 * <p>This avoids ambiguity for the user, essentially having two buttons available to open the exact same menu.</p>
 * <p>It should run in onCreate() method and before setContentView().</p>
 *//* www.  ja va 2  s.  c om*/
public void setOverflowMenuAvailable() {
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.cubusmail.user.UserAccountDao.java

/**
 * @param preferencesJson// ww w  . j a  v  a 2  s .  c o m
 * @param preferences
 */
private void json2Preferences(String preferencesJson, Preferences preferences) {

    try {
        JSONObject object = new JSONObject(preferencesJson);
        Field[] fields = Preferences.class.getFields();
        if (fields != null) {
            for (Field field : fields) {
                Object value = object.has(field.getName()) ? object.get(field.getName()) : null;
                if (value != null) {
                    if (value instanceof Integer) {
                        field.setInt(preferences, ((Integer) value).intValue());
                    } else if (value instanceof Boolean) {
                        field.setBoolean(preferences, ((Boolean) value).booleanValue());
                    } else if (value instanceof String) {
                        field.set(preferences, value);
                    }
                }
            }
        }
    } catch (JSONException e) {
        logger.error(e.getMessage(), e);
    } catch (NumberFormatException e) {
        logger.error(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        logger.error(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.apache.pig.backend.hadoop.executionengine.tez.TezLauncher.java

@Override
public PigStats launchPig(PhysicalPlan php, String grpName, PigContext pc) throws Exception {
    synchronized (this) {
        if (executor == null) {
            executor = Executors.newSingleThreadExecutor(namedThreadFactory);
        }/*  ww  w . j  a va 2 s . com*/
    }
    if (pc.getExecType().isLocal()) {
        pc.getProperties().setProperty(TezConfiguration.TEZ_LOCAL_MODE, "true");
        pc.getProperties().setProperty(TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_LOCAL_FETCH, "true");
        pc.getProperties().setProperty(TezConfiguration.TEZ_IGNORE_LIB_URIS, "true");
        pc.getProperties().setProperty(TezConfiguration.TEZ_AM_DAG_SCHEDULER_CLASS,
                DAGSchedulerNaturalOrderControlled.class.getName());
    }
    Configuration conf = ConfigurationUtil.toConfiguration(pc.getProperties(), true);
    // Make sure MR counter does not exceed limit
    if (conf.get(TezConfiguration.TEZ_COUNTERS_MAX) != null) {
        conf.setInt(org.apache.hadoop.mapreduce.MRJobConfig.COUNTERS_MAX_KEY,
                Math.max(conf.getInt(org.apache.hadoop.mapreduce.MRJobConfig.COUNTERS_MAX_KEY, 0),
                        conf.getInt(TezConfiguration.TEZ_COUNTERS_MAX, 0)));
    }
    if (conf.get(TezConfiguration.TEZ_COUNTERS_MAX_GROUPS) != null) {
        conf.setInt(org.apache.hadoop.mapreduce.MRJobConfig.COUNTER_GROUPS_MAX_KEY,
                Math.max(conf.getInt(org.apache.hadoop.mapreduce.MRJobConfig.COUNTER_GROUPS_MAX_KEY, 0),
                        conf.getInt(TezConfiguration.TEZ_COUNTERS_MAX_GROUPS, 0)));
    }

    // This is hacky, but Limits cannot be initialized twice
    try {
        Field f = Limits.class.getDeclaredField("isInited");
        f.setAccessible(true);
        f.setBoolean(null, false);
        Limits.init(conf);
    } catch (Throwable e) {
        log.warn("Error when setting counter limit: " + e.getMessage());
    }

    if (pc.defaultParallel == -1 && !conf.getBoolean(PigConfiguration.PIG_TEZ_AUTO_PARALLELISM, true)) {
        pc.defaultParallel = 1;
    }
    aggregateWarning = conf.getBoolean("aggregate.warning", false);

    TezResourceManager tezResourceManager = TezResourceManager.getInstance();
    tezResourceManager.init(pc, conf);

    String stagingDir = conf.get(TezConfiguration.TEZ_AM_STAGING_DIR);
    String resourcesDir = tezResourceManager.getResourcesDir().toString();
    if (stagingDir == null) {
        // If not set in tez-site.xml, use Pig's tez resources directory as staging directory
        // instead of TezConfiguration.TEZ_AM_STAGING_DIR_DEFAULT
        stagingDir = resourcesDir;
        conf.set(TezConfiguration.TEZ_AM_STAGING_DIR, resourcesDir);
    }
    log.info("Tez staging directory is " + stagingDir + " and resources directory is " + resourcesDir);

    List<TezOperPlan> processedPlans = new ArrayList<TezOperPlan>();

    tezScriptState = TezScriptState.get();
    tezStats = new TezPigScriptStats(pc);
    PigStats.start(tezStats);

    conf.set(TezConfiguration.TEZ_USE_CLUSTER_HADOOP_LIBS, "true");
    TezJobCompiler jc = new TezJobCompiler(pc, conf);
    TezPlanContainer tezPlanContainer = compile(php, pc);

    tezStats.initialize(tezPlanContainer);
    tezScriptState.emitInitialPlanNotification(tezPlanContainer);
    tezScriptState.emitLaunchStartedNotification(tezPlanContainer.size()); //number of DAGs to Launch

    boolean stop_on_failure = Boolean.valueOf(pc.getProperties().getProperty("stop.on.failure", "false"));
    boolean stoppedOnFailure = false;

    TezPlanContainerNode tezPlanContainerNode;
    TezOperPlan tezPlan;
    int processedDAGs = 0;
    while ((tezPlanContainerNode = tezPlanContainer.getNextPlan(processedPlans)) != null) {
        tezPlan = tezPlanContainerNode.getTezOperPlan();
        processLoadAndParallelism(tezPlan, pc);
        processedPlans.add(tezPlan);
        ProgressReporter reporter = new ProgressReporter(tezPlanContainer.size(), processedDAGs);
        if (tezPlan.size() == 1 && tezPlan.getRoots().get(0) instanceof NativeTezOper) {
            // Native Tez Plan
            NativeTezOper nativeOper = (NativeTezOper) tezPlan.getRoots().get(0);
            tezScriptState.emitJobsSubmittedNotification(1);
            nativeOper.runJob(tezPlanContainerNode.getOperatorKey().toString());
        } else {
            TezPOPackageAnnotator pkgAnnotator = new TezPOPackageAnnotator(tezPlan);
            pkgAnnotator.visit();

            runningJob = jc.compile(tezPlanContainerNode, tezPlanContainer);
            //TODO: Exclude vertex groups from numVerticesToLaunch ??
            tezScriptState.dagLaunchNotification(runningJob.getName(), tezPlan, tezPlan.size());
            runningJob.setPigStats(tezStats);

            // Set the thread UDFContext so registered classes are available.
            final UDFContext udfContext = UDFContext.getUDFContext();
            Runnable task = new Runnable() {
                @Override
                public void run() {
                    Thread.currentThread().setContextClassLoader(PigContext.getClassLoader());
                    UDFContext.setUdfContext(udfContext.clone());
                    runningJob.run();
                }
            };

            // Mark the times that the jobs were submitted so it's reflected in job
            // history props. TODO: Fix this. unused now
            long scriptSubmittedTimestamp = System.currentTimeMillis();
            // Job.getConfiguration returns the shared configuration object
            Configuration jobConf = runningJob.getConfiguration();
            jobConf.set("pig.script.submitted.timestamp", Long.toString(scriptSubmittedTimestamp));
            jobConf.set("pig.job.submitted.timestamp", Long.toString(System.currentTimeMillis()));

            Future<?> future = executor.submit(task);
            tezScriptState.emitJobsSubmittedNotification(1);

            boolean jobStarted = false;

            while (!future.isDone()) {
                if (!jobStarted && runningJob.getApplicationId() != null) {
                    jobStarted = true;
                    String appId = runningJob.getApplicationId().toString();
                    //For Oozie Pig action job id matching compatibility with MR mode
                    log.info("HadoopJobId: " + appId.replace("application", "job"));
                    tezScriptState.emitJobStartedNotification(appId);
                    tezScriptState.dagStartedNotification(runningJob.getName(), appId);
                }
                reporter.notifyUpdate();
                Thread.sleep(1000);
            }
            // For tez_local mode where PigProcessor destroys all UDFContext
            UDFContext.setUdfContext(udfContext);
            try {
                // In case of FutureTask there is no uncaught exception
                // Need to do future.get() to get any exception
                future.get();
            } catch (ExecutionException e) {
                setJobException(e.getCause());
            }
        }
        processedDAGs++;
        if (tezPlanContainer.size() == processedDAGs) {
            tezScriptState.emitProgressUpdatedNotification(100);
        } else {
            tezScriptState.emitProgressUpdatedNotification(
                    ((tezPlanContainer.size() - processedDAGs) / tezPlanContainer.size()) * 100);
        }
        handleUnCaughtException(pc);
        boolean tezDAGSucceeded = reporter.notifyFinishedOrFailed();
        tezPlanContainer.updatePlan(tezPlan, tezDAGSucceeded);
        // if stop_on_failure is enabled, we need to stop immediately when any job has failed
        if (!tezDAGSucceeded) {
            if (stop_on_failure) {
                stoppedOnFailure = true;
                break;
            } else {
                log.warn("Ooops! Some job has failed! Specify -stop_on_failure if you "
                        + "want Pig to stop immediately on failure.");
            }
        }
    }

    tezStats.finish();
    tezScriptState.emitLaunchCompletedNotification(tezStats.getNumberSuccessfulJobs());

    for (OutputStats output : tezStats.getOutputStats()) {
        POStore store = output.getPOStore();
        try {
            if (!output.isSuccessful()) {
                store.getStoreFunc().cleanupOnFailure(store.getSFile().getFileName(),
                        Job.getInstance(output.getConf()));
            } else {
                store.getStoreFunc().cleanupOnSuccess(store.getSFile().getFileName(),
                        Job.getInstance(output.getConf()));
            }
        } catch (IOException e) {
            throw new ExecException(e);
        } catch (AbstractMethodError nsme) {
            // Just swallow it.  This means we're running against an
            // older instance of a StoreFunc that doesn't implement
            // this method.
        }
    }

    if (stoppedOnFailure) {
        throw new ExecException("Stopping execution on job failure with -stop_on_failure option", 6017,
                PigException.REMOTE_ENVIRONMENT);
    }

    return tezStats;
}

From source file:com.klinker.android.twitter.ui.drawer_activities.discover.trends.SearchedTrendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.activity_slide_up, R.anim.activity_slide_down);

    try {//from   w  w w  .  j ava 2  s  . c om
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

    context = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    settings = AppSettings.getInstance(this);

    if (settings.advanceWindowed) {
        setUpWindow();
    }

    Utils.setUpPopupTheme(context, settings);

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.search));

    setContentView(R.layout.ptr_list_layout);

    mPullToRefreshLayout = (FullScreenSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    mPullToRefreshLayout.setOnRefreshListener(new FullScreenSwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            onRefreshStarted();
        }
    });

    if (settings.addonTheme) {
        mPullToRefreshLayout.setColorScheme(settings.accentInt, SwipeProgressBar.COLOR2, settings.accentInt,
                SwipeProgressBar.COLOR3);
    } else {
        if (settings.theme != AppSettings.THEME_LIGHT) {
            mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color),
                    SwipeProgressBar.COLOR2, context.getResources().getColor(R.color.app_color),
                    SwipeProgressBar.COLOR3);
        } else {
            mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color),
                    getResources().getColor(R.color.light_ptr_1),
                    context.getResources().getColor(R.color.app_color),
                    getResources().getColor(R.color.light_ptr_2));
        }
    }

    listView = (AsyncListView) findViewById(R.id.listView);

    BitmapLruCache cache = App.getInstance(context).getBitmapCache();
    ArrayListLoader loader = new ArrayListLoader(cache, context);

    ItemManager.Builder builder = new ItemManager.Builder(loader);
    builder.setPreloadItemsEnabled(true).setPreloadItemsCount(50);
    builder.setThreadPoolSize(4);

    listView.setItemManager(builder.build());

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            final int lastItem = firstVisibleItem + visibleItemCount;
            if (lastItem == totalItemCount && canRefresh) {
                getMore();
            }
        }
    });

    spinner = (LinearLayout) findViewById(R.id.list_progress);
    spinner.setVisibility(View.GONE);

    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

    }

    handleIntent(getIntent());

    Utils.setActionBar(context);

}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.activity_slide_up, R.anim.activity_slide_down);

    try {/*from  w ww  .java 2s.  c  o  m*/
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

    context = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    settings = AppSettings.getInstance(this);

    if (settings.advanceWindowed) {
        setUpWindow();
    }

    Utils.setUpPopupTheme(context, settings);

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.search));

    setContentView(R.layout.ptr_list_layout);

    mPullToRefreshLayout = (FullScreenSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    mPullToRefreshLayout.setOnRefreshListener(new FullScreenSwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            onRefreshStarted();
        }
    });

    if (settings.addonTheme) {
        mPullToRefreshLayout.setColorScheme(settings.accentInt, SwipeProgressBar.COLOR2, settings.accentInt,
                SwipeProgressBar.COLOR3);
    } else {
        if (settings.theme != AppSettings.THEME_LIGHT) {
            mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color),
                    SwipeProgressBar.COLOR2, context.getResources().getColor(R.color.app_color),
                    SwipeProgressBar.COLOR3);
        } else {
            mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color),
                    getResources().getColor(R.color.light_ptr_1),
                    context.getResources().getColor(R.color.app_color),
                    getResources().getColor(R.color.light_ptr_2));
        }
    }

    listView = (AsyncListView) findViewById(R.id.listView);

    BitmapLruCache cache = App.getInstance(context).getBitmapCache();
    ArrayListLoader loader = new ArrayListLoader(cache, context);

    ItemManager.Builder builder = new ItemManager.Builder(loader);
    builder.setPreloadItemsEnabled(true).setPreloadItemsCount(50);
    builder.setThreadPoolSize(4);

    listView.setItemManager(builder.build());

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            final int lastItem = firstVisibleItem + visibleItemCount;
            if (lastItem == totalItemCount && canRefresh) {
                getMore();
            }
        }
    });

    spinner = (LinearLayout) findViewById(R.id.list_progress);
    spinner.setVisibility(View.GONE);

    handleIntent(getIntent());

    Utils.setActionBar(context);

}

From source file:org.alex73.skarynka.scan.Book2.java

private void set(Object obj, String fieldName, String value, String debug) {
    try {/*from  ww  w  .j av  a 2  s.co m*/
        Field f = obj.getClass().getField(fieldName);
        if (!Modifier.isPublic(f.getModifiers()) || Modifier.isStatic(f.getModifiers())
                || Modifier.isTransient(f.getModifiers())) {
            errors.add("Field is not public for '" + debug + "'");
            return;
        }
        if (f.getType() == int.class) {
            f.setInt(obj, Integer.parseInt(value));
        } else if (f.getType() == boolean.class) {
            f.setBoolean(obj, Boolean.parseBoolean(value));
        } else if (f.getType() == String.class) {
            f.set(obj, value);
        } else if (Set.class.isAssignableFrom(f.getType())) {
            TreeSet<String> v = new TreeSet<>(Arrays.asList(value.split(";")));
            f.set(obj, v);
        } else {
            errors.add("Unknown field class for set '" + debug + "'");
            return;
        }
    } catch (NoSuchFieldException ex) {
        errors.add("Unknown field for set '" + debug + "'");
    } catch (IllegalAccessException ex) {
        errors.add("Wrong field for set '" + debug + "'");
    } catch (Exception ex) {
        errors.add("Error set value to field for '" + debug + "'");
    }
}

From source file:ma.wanam.xtouchwiz.XTouchWizActivity.java

private void initScreen() {

    try {//from w  w w . j ava 2 s.  c om
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Throwable t) {
        // Ignore
    }
}

From source file:com.layer8apps.MyTlc.java

/************
 *  PURPOSE: Primary thread that starts everything
 *  ARGUMENTS: <Bundle> savedInstanceState
 *  RETURNS: void//from  ww w.j a v  a  2 s.  com
 *  AUTHOR: Casey Stark <starkca90@gmail.com>, Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com>
 ************/
@Override
public void onCreate(Bundle savedInstanceState) {
    /*************
     * The following try statement makes the app think that the user doesn't
     * have a hard settings button.  This allows the options menu to always be
     * visible
     ************/
    try {
        // Get the configuration of the device
        ViewConfiguration config = ViewConfiguration.get(this);
        // Check if the phone has a hard settings key
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        // If it does...
        if (menuKeyField != null) {
            // Make our app think it doesn't!
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Do nothing
    }

    // Create a new preferences manager
    pf = new Preferences(this);

    // Set the theme of the app
    applyTheme();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    txtUsername = (EditText) findViewById(R.id.txtUsername);
    txtUsername.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    txtPassword = (EditText) findViewById(R.id.txtPassword);
    remember = (CheckBox) findViewById(R.id.remember);
    results = (TextView) findViewById(R.id.results);

    // Get a reference to our last handler
    final Object handler = getLastCustomNonConfigurationInstance();
    // If the last handler existed
    if (handler != null) {
        // Cast the handler to MyHandler so we can use it
        mHandler = (MyHandler) handler;
    } else {
        // Otherwise create a new handler
        mHandler = new MyHandler();
    }
    // Assign the activity for our handler so it knows the proper reference
    mHandler.setActivity(this);

    // Load all of the users saved options
    checkSavedSettings();

    // Show the ads
    showAds();
}

From source file:me.henrytao.observableorm.orm.ObservableModel.java

public T deserialize(Map<String, Object> map) throws IllegalAccessException {
    Field[] fields = getDeclaredFields();
    for (Field f : fields) {
        if (!f.isAnnotationPresent(Column.class)) {
            continue;
        }/*from   w ww. j  a  v  a  2  s. c  o m*/
        Column column = f.getAnnotation(Column.class);
        if (!column.deserialize()) {
            continue;
        }
        f.setAccessible(true);
        String name = column.name();
        Object value = map.get(name);
        Class type = f.getType();
        Deserializer deserializer = deserializerMap.get(type);
        if (deserializer != null) {
            f.set(this, deserializer.deserialize(value));
        } else if (boolean.class.isAssignableFrom(type)) {
            f.setBoolean(this, value == null ? false : (Boolean) value);
        } else if (double.class.isAssignableFrom(type)) {
            f.setDouble(this, value == null ? 0.0 : (Double) value);
        } else if (float.class.isAssignableFrom(type)) {
            f.setFloat(this, value == null ? 0f : (Float) value);
        } else if (int.class.isAssignableFrom(type)) {
            f.setInt(this, value == null ? 0 : (int) value);
        } else if (short.class.isAssignableFrom(type)) {
            f.setShort(this, value == null ? 0 : (short) value);
        } else if (byte.class.isAssignableFrom(type)) {
            f.setByte(this, value == null ? 0 : (byte) value);
        } else if (String.class.isAssignableFrom(type)) {
            f.set(this, value);
        } else if (JSONObject.class.isAssignableFrom(type)) {
            // todo: nested object should be another model
        }
    }
    return (T) this;
}