private void check (String text, Object object) { Object object2 = json.fromJson(object.getClass(), text); equals(object, object2); }
/** Adds all resources in the specified skin JSON file. */ public void load (FileHandle skinFile) { try { getJsonLoader(skinFile).fromJson(Skin.class, skinFile); } catch (SerializationException ex) { throw new SerializationException("Error reading file: " + skinFile, ex); } }
/** Adds all resources in the specified skin JSON file. */ public void load (FileHandle skinFile) { try { getJsonLoader(skinFile).fromJson(Skin.class, skinFile); } catch (SerializationException ex) { throw new SerializationException("Error reading file: " + skinFile, ex); } }
static public void main (String[] args) throws Exception { Settings settings = null; String input = null, output = null, packFileName = "pack.atlas"; switch (args.length) { case 4: settings = new Json().fromJson(Settings.class, new FileReader(args[3])); case 3: packFileName = args[2]; case 2: output = args[1]; case 1: input = args[0]; break; default: System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]"); System.exit(0); } if (output == null) { File inputFile = new File(input); output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath(); } if (settings == null) settings = new Settings(); process(settings, input, output, packFileName); } }
static public void main (String[] args) throws Exception { Settings settings = null; String input = null, output = null, packFileName = "pack.atlas"; switch (args.length) { case 4: settings = new Json().fromJson(Settings.class, new FileReader(args[3])); case 3: packFileName = args[2]; case 2: output = args[1]; case 1: input = args[0]; break; default: System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]"); System.exit(0); } if (output == null) { File inputFile = new File(input); output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath(); } if (settings == null) settings = new Settings(); process(settings, input, output, packFileName); } }
private void testObjectGraph (TestMapGraph object, String typeName) { Json json = new Json(); json.setTypeName(typeName); json.setUsePrototypes(false); json.setIgnoreUnknownFields(true); json.setOutputType(OutputType.json); String text = json.prettyPrint(object); TestMapGraph object2 = json.fromJson(TestMapGraph.class, text); if (object2.map.size() != object.map.size()) { throw new RuntimeException("Too many items in deserialized json map."); } if (object2.objectMap.size != object.objectMap.size) { throw new RuntimeException("Too many items in deserialized json object map."); } if (object2.arrayMap.size != object.arrayMap.size) { throw new RuntimeException("Too many items in deserialized json map."); } }
@Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ParticleEffectLoadParameter parameter) { Json json = new Json(); ResourceData<ParticleEffect> data = json.fromJson(ResourceData.class, file); Array<AssetData> assets = null; synchronized (items) { ObjectMap.Entry<String, ResourceData<ParticleEffect>> entry = new ObjectMap.Entry<String, ResourceData<ParticleEffect>>(); entry.key = fileName; entry.value = data; items.add(entry); assets = data.getAssets(); } Array<AssetDescriptor> descriptors = new Array<AssetDescriptor>(); for (AssetData<?> assetData : assets) { // If the asset doesn't exist try to load it from loading effect directory if (!resolve(assetData.filename).exists()) { assetData.filename = file.parent().child(Gdx.files.internal(assetData.filename).name()).path(); } if (assetData.type == ParticleEffect.class) { descriptors.add(new AssetDescriptor(assetData.filename, assetData.type, parameter)); } else descriptors.add(new AssetDescriptor(assetData.filename, assetData.type)); } return descriptors; }
@Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ParticleEffectLoadParameter parameter) { Json json = new Json(); ResourceData<ParticleEffect> data = json.fromJson(ResourceData.class, file); Array<AssetData> assets = null; synchronized (items) { ObjectMap.Entry<String, ResourceData<ParticleEffect>> entry = new ObjectMap.Entry<String, ResourceData<ParticleEffect>>(); entry.key = fileName; entry.value = data; items.add(entry); assets = data.getAssets(); } Array<AssetDescriptor> descriptors = new Array<AssetDescriptor>(); for (AssetData<?> assetData : assets) { // If the asset doesn't exist try to load it from loading effect directory if (!resolve(assetData.filename).exists()) { assetData.filename = file.parent().child(Gdx.files.internal(assetData.filename).name()).path(); } if (assetData.type == ParticleEffect.class) { descriptors.add(new AssetDescriptor(assetData.filename, assetData.type, parameter)); } else descriptors.add(new AssetDescriptor(assetData.filename, assetData.type)); } return descriptors; }
Vector2 fromJson = json.fromJson(Vector2.class, jsonString); println("JSON serialized: " + jsonString); println("JSON deserialized: " + fromJson);
/** * @param type May be null if the type is unknown. * @param json * @return May be null. */ @Override public <T> T fromJson(Class<T> type, String json) { return super.fromJson(type, LZSPlus.decompress(json)); }
/** * @param type May be null if the type is unknown. * @param elementType * @param json * @return May be null. */ @Override public <T> T fromJson(Class<T> type, Class elementType, String json) { return super.fromJson(type, elementType, LZSPlus.decompress(json)); } }
/** Adds all resources in the specified skin JSON file. */ public void load (FileHandle skinFile) { try { getJsonLoader(skinFile).fromJson(Skin.class, skinFile); } catch (SerializationException ex) { throw new SerializationException("Error reading file: " + skinFile, ex); } }
public FileHandle loadLastDirectory () { String data = prefs.getString(lastDirKeyName, null); if (data == null) return null; return json.fromJson(FileHandleData.class, data).toFileHandle(); }
/** * @param type May be null if the type is unknown. * @param file * @return May be null. */ @Override public <T> T fromJson(Class<T> type, FileHandle file) { return super.fromJson(type, LZSPlus.decompress(file.readString("UTF-8"))); }
/** * @param type May be null if the type is unknown. * @param elementType May be null if the type is unknown. * @param file * @return May be null. */ @Override public <T> T fromJson(Class<T> type, Class elementType, FileHandle file) { return super.fromJson(type, elementType, LZSPlus.decompress(file.readString("UTF-8"))); }
private static AseFormat fromJson(FileHandle jsonFile) { final Json json = new Json(); json.setIgnoreUnknownFields(true); return json.fromJson(AseFormat.class, jsonFile); }
public Array<FileHandle> loadRecentDirectories () { String data = prefs.getString(recentDirKeyName, null); if (data == null) return new Array<FileHandle>(); else return json.fromJson(FileArrayData.class, data).toFileHandleArray(); }
public Array<FileHandle> loadFavorites () { String data = prefs.getString(favoritesKeyName, null); if (data == null) return new Array<FileHandle>(); else return json.fromJson(FileArrayData.class, data).toFileHandleArray(); }
@Initiate(priority = AutumnActionPriority.TOP_PRIORITY) void init() { modulesDir.mkdirs(); if (repoCacheFile.exists()) { Array<RepositoryModuleData> newArray = json.fromJson(Array.class, RepositoryModuleData.class, repoCacheFile); repositoryModules.clear(); for (RepositoryModuleData moduleData : newArray) { repositoryModules.put(moduleData.name, moduleData); } Gdx.app.log(TAG, "Cached data was loaded"); } requestRefreshRepositoryIfNeeded(); }
@Override public void read(Json json, JsonValue jsonData) { try { type = ClassReflection.forName(jsonData.get("type").asString()); } catch (Exception e) { type = null; } path = jsonData.get("path").asString(); JsonValue parametersValue = jsonData.get("parameters"); parameters = parametersValue != null ? json.fromJson(AssetLoaderParameters.class, parametersValue.toString()) : null; } }