Advertisement
Guest User

json serializable

a guest
Apr 11th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package ch.digitalmeat.bot.data.game;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.utils.Json;
  5. import com.badlogic.gdx.utils.Json.Serializable;
  6. import com.badlogic.gdx.utils.JsonValue;
  7.  
  8.  
  9. public class Station implements Serializable {
  10.    public String key;
  11.    public String name;
  12.    public StationType type;
  13.  
  14.    public ResourceLevels levels = new ResourceLevels();
  15.  
  16.    @Override
  17.    public void write(Json json) {
  18.       json.writeValue("key", key);
  19.       json.writeValue("name", name);
  20.       json.writeValue("type", type);
  21.       json.writeValue("levels", levels);
  22.    }
  23.  
  24.    @Override
  25.    public void read(Json json, JsonValue data) {
  26.       key = data.getString("key");
  27.       name = data.getString("type");
  28.       type = json.readValue("type", StationType.class, data);
  29.       levels = json.readValue("levels", ResourceLevels.class, data);
  30.    }
  31.  
  32.    public static Station read(String file) {
  33.       Json json = new Json();
  34.       return json.fromJson(Station.class, Gdx.files.internal(file));
  35.    }
  36.  
  37.    public static void save(Station station, String file) {
  38.       Json json = new Json();
  39.       json.toJson(station, Gdx.files.local(file));
  40.    }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement