model.BaseModel.java Source code

Java tutorial

Introduction

Here is the source code for model.BaseModel.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.lang.reflect.Field;
import org.json.simple.JSONObject;

/**
 *
 * @author roman
 */
abstract public class BaseModel {

    public boolean setAttribute(String key, String value) {
        try {
            Field field = this.getClass().getDeclaredField(key);
            field.setAccessible(true);
            field.set(this, value);
        } catch (SecurityException | IllegalAccessException | NoSuchFieldException ex) {
            return false;
        }
        return true;
    }

    abstract public void load(JSONObject item);
}