Java Code Examples for com.badlogic.gdx.utils.Json#toJson()

The following examples show how to use com.badlogic.gdx.utils.Json#toJson() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Recorder.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public void save() {

		Json json = new Json();

		// String s = json.prettyPrint(list);
		String s = json.toJson(list, ArrayList.class, TimeVerb.class);
		s = json.prettyPrint(s);

		Writer w = EngineAssetManager.getInstance().getUserFile(fileName + RECORD_EXT).writer(false, "UTF-8");

		try {
			w.write(s);
			w.close();
		} catch (IOException e) {
			EngineLogger.error("ERROR SAVING RECORD", e);
		}
	}
 
Example 2
Source File: StringGenerator.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
public static String dataToString(Object object) {
    if (isPrimitiveType(object))
        return object.toString();
    Json json = new Json();
    json.setTypeName(null);
    json.setQuoteLongValues(false);
    json.setIgnoreUnknownFields(true);
    json.setOutputType(JsonWriter.OutputType.json);
    return json.toJson(object);
}
 
Example 3
Source File: MapTransformer.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
static String mapToJSON(Map<String, Object> map) {
    Json json = new Json();
    json.setTypeName(null);
    json.setQuoteLongValues(true);
    json.setIgnoreUnknownFields(true);
    json.setOutputType(JsonWriter.OutputType.json);
    return json.toJson(map, HashMap.class);
}
 
Example 4
Source File: JsonDataModifier.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
/**
 * Returns modified json data.
 *
 * @param oldJsonData Old data as json string.
 * @return New data as json string
 */
@SuppressWarnings("unchecked")
public String modify(String oldJsonData) {
    T oldData = JsonProcessor.process(wantedType, oldJsonData);
    T newData = (T) transactionFunction.apply(oldData);
    Json json = new Json();
    json.setTypeName(null);
    json.setQuoteLongValues(true);
    json.setIgnoreUnknownFields(true);
    json.setOutputType(JsonWriter.OutputType.json);
    return json.toJson(newData, wantedType);
}
 
Example 5
Source File: ProfileManagerGDX.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void persist(P profile) {
    FileHandle profileDataFile = Gdx.files.local(preferencesManager.PROFILE_DATA_FILE);
    Json json = new Json();
    String profileAsText = json.toJson(profile);

    profileAsText = Base64Coder.encodeString(profileAsText);
    profileDataFile.writeString(profileAsText, false);
}
 
Example 6
Source File: HighScoreManager.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
private void persist() {
	FileHandle highScoresFile = Gdx.files.local(SCORES_DATA_FILE);
	
       Json json = new Json();
       String scoresStr = json.toJson(highScores);
       String encScoresStr = Base64Coder.encodeString(scoresStr);
       highScoresFile.writeString(encScoresStr, false);		
}
 
Example 7
Source File: StateManager.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public void persist(GameScreenState gameScreenState, GameState gameState) {
       FileHandle stateDataFile = Gdx.files.local(STATE_DATA_FILE);
       
       StateBundle stBundle = new StateBundle();
       stBundle.gameScreenState = gameScreenState;
       stBundle.gameState = gameState;
       
       Json json = new Json();
       String state = json.toJson(stBundle);
       stateDataFile.writeString(state, false);
       
       //Gdx.app.log("GameScreen", state);
}
 
Example 8
Source File: WorldSerialization.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void saveGameState(String filename, boolean screenshot) throws IOException {
	EngineLogger.debug("SAVING GAME STATE");

	if (w.isDisposed())
		return;

	Json json = new BladeJson(w, Mode.STATE);
	json.setOutputType(OutputType.javascript);
	json.setSortFields(true);

	String s = null;

	if (EngineLogger.debugMode())
		s = json.prettyPrint(this);
	else
		s = json.toJson(this);

	Writer writer = EngineAssetManager.getInstance().getUserFile(filename).writer(false, "UTF-8");

	try {
		writer.write(s);
		writer.flush();
	} catch (IOException e) {
		throw new IOException("ERROR SAVING GAME", e);
	} finally {
		writer.close();
	}

	// Save Screenshot
	if (screenshot)
		w.takeScreenshot(filename + ".png", SCREENSHOT_DEFAULT_WIDTH);
}
 
Example 9
Source File: Recorder.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private void writeJson() {
	Json json = new Json();
	String data = json.toJson(history);
	FileHandle fh = Gdx.files.external(demoDir + "history.json.gz");
	byte[] bytes = Compression.writeCompressedString(data);
	if (bytes == null) {
		Log.error("Could not write compressed playback (JSON)");
	} else {
		int byteCount = bytes.length;
		fh.writeBytes(bytes, false);
		Log.debug("Wrote compressed playback: " + byteCount + " bytes");
	}
}
 
Example 10
Source File: HighScoreManager.java    From FruitCatcher with Apache License 2.0 4 votes vote down vote up
public static String serialize(List<HighScore> highScores) {
       Json json = new Json();
       String scoresStr = json.toJson(highScores);
       return scoresStr;
}