本文整理匯總了Java中com.badlogic.gdx.utils.Json.setIgnoreUnknownFields方法的典型用法代碼示例。如果您正苦於以下問題:Java Json.setIgnoreUnknownFields方法的具體用法?Java Json.setIgnoreUnknownFields怎麽用?Java Json.setIgnoreUnknownFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.utils.Json
的用法示例。
在下文中一共展示了Json.setIgnoreUnknownFields方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
/**
* Converts json string into java object.
*
* @param wantedType Wanted type
* @param genericTypeKeeper Object with wanted type inside generic argument
* @param jsonString Json string data
* @param <R> Return type
* @return
*/
public static <R> R process(Class<?> wantedType, Object genericTypeKeeper, String jsonString)
{
Json json = new Json();
json.setIgnoreUnknownFields(true);
json.setTypeName(null);
R result = null;
if (ClassReflection.isAssignableFrom(List.class, wantedType)
|| ClassReflection.isAssignableFrom(Map.class, wantedType)) {
NestedGenericType nestedGenericType = AnnotationProcessor.getNestedGenericTypeAnnotation(genericTypeKeeper);
if (nestedGenericType == null) throw new NestedGenericTypeAnnotationMissingException();
json.setDefaultSerializer(new JsonListMapDeserializer(wantedType, nestedGenericType.value()));
result = (R) json.fromJson(wantedType, jsonString);
} else {
result = (R) json.fromJson(wantedType, jsonString);
}
return result;
}
示例2: readReplayData
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
/**
* リプレイデータを読み込む
*
* @param model
* 対象のBMS
* @param lnmode
* LNモード
* @return リプレイデータ
*/
public ReplayData readReplayData(BMSModel model, int lnmode, int index) {
if (existsReplayData(model, lnmode, index)) {
Json json = new Json();
json.setIgnoreUnknownFields(true);
try {
String path = this.getReplayDataFilePath(model, lnmode, index);
if (Files.exists(Paths.get(path + ".brd"))) {
return json.fromJson(ReplayData.class, new BufferedInputStream(
new GZIPInputStream(Files.newInputStream(Paths.get(path + ".brd")))));
}
if (Files.exists(Paths.get(path + ".json"))) {
return json.fromJson(ReplayData.class, new FileReader(path + ".json"));
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
示例3: dataToString
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
/**
* Returns JSON string representation of object.
* <p>
* It using libgdx {@link Json} class.
*
* @param object Any object
* @return JSON string representation of {@code object}
*/
public static String dataToString(Object object)
{
if (isPrimitiveType(object))
return object.toString();
Json json = new Json();
json.setTypeName(null);
json.setQuoteLongValues(true);
json.setIgnoreUnknownFields(true);
json.setOutputType(JsonWriter.OutputType.json);
return json.toJson(object);
}
示例4: mapToJSON
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
/**
* @param map Map, not null
* @return JSON representation of given map
*/
public 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);
}
示例5: modify
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
/**
* Returns modified json data.
*
* @param oldJsonData Old data as json string.
* @return New data as json string
*/
public String modify(String oldJsonData)
{
R oldData = JsonProcessor.process(wantedType, transactionCallback, oldJsonData);
R newData = transactionCallback.run(oldData);
Json json = new Json();
json.setTypeName(null);
json.setQuoteLongValues(true);
json.setIgnoreUnknownFields(true);
json.setOutputType(JsonWriter.OutputType.json);
return json.toJson(newData, wantedType);
}
示例6: toNSDictionary
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static NSDictionary toNSDictionary(Object object)
{
if (object instanceof Map) {
return toNSDictionary((Map) object);
} else {
String objectJsonData = new Json().toJson(object);
Json json = new Json();
json.setIgnoreUnknownFields(true);
Map objectMap = json.fromJson(HashMap.class, objectJsonData);
return toNSDictionary(objectMap);
}
}
示例7: readPlayerConfig
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
public static PlayerConfig readPlayerConfig(String playerid) {
PlayerConfig player = new PlayerConfig();
Path p = Paths.get("player/" + playerid + "/config.json");
Json json = new Json();
try {
json.setIgnoreUnknownFields(true);
player = json.fromJson(PlayerConfig.class, new FileReader(p.toFile()));
player.setId(playerid);
player.validate();
} catch(Throwable e) {
e.printStackTrace();
}
return player;
}
示例8: includeArray
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
private void includeArray(Json json, JsonValue jsonValue, Class cls, ArrayList<T> items) {
Json subJson = new Json();
subJson.setIgnoreUnknownFields(true);
File file = getPath(path.getParent().toString() + "/" + jsonValue.get("include").asString(), filemap);
if (file.exists()) {
setSerializers(subJson, this.options, file.toPath());
try {
T[] array = (T[])subJson.fromJson(cls, new FileReader(file));
Collections.addAll(items, array);
} catch (FileNotFoundException e) {
}
}
}
示例9: getResources
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
public static List<String> getResources(FileHandle jsonFile) {
dirName = jsonFile.parent().toString();
if (!dirName.equals("")) {
dirName += File.separator;
}
String json = jsonFile.readString("utf-8");
Json jj = new Json();
jj.setIgnoreUnknownFields(true);
CCExport export = jj.fromJson(CCExport.class, json);
return export.getContent().getContent().getUsedResources();
}
示例10: save
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
public void save (FileHandle handle) {
Json json = new Json();
json.setOutputType(OutputType.json);
json.setTypeName(null);
json.setUsePrototypes(false);
json.setIgnoreUnknownFields(true);
json.setOutputType(OutputType.json);
handle.child("project.json").writeString(json.prettyPrint(this), false);
}
示例11: CocoStudioUIEditor
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
/**
* @param jsonFile ui編輯成生成的json文件
* @param textureAtlas 資源文件,傳入 null表示使用小文件方式加載圖片.
* @param ttfs 字體文件集合
* @param bitmapFonts 自定義字體文件集合
* @param defaultFont 默認ttf字體文件
*/
public CocoStudioUIEditor(FileHandle jsonFile,
Map<String, FileHandle> ttfs, Map<String, BitmapFont> bitmapFonts,
FileHandle defaultFont, Collection<TextureAtlas> textureAtlas) {
this.textureAtlas = textureAtlas;
this.ttfs = ttfs;
this.bitmapFonts = bitmapFonts;
this.defaultFont = defaultFont;
parsers = new HashMap<>();
addParser(new CCButton());
addParser(new CCCheckBox());
addParser(new CCImageView());
addParser(new CCLabel());
addParser(new CCLabelBMFont());
addParser(new CCPanel());
addParser(new CCScrollView());
addParser(new CCTextField());
addParser(new CCLoadingBar());
addParser(new CCTextAtlas());
addParser(new CCLayer());
addParser(new CCLabelAtlas());
addParser(new CCSpriteView());
addParser(new CCNode());
addParser(new CCSlider());
addParser(new CCParticle());
addParser(new CCProjectNode());
addParser(new CCPageView());
addParser(new CCTImageView());
actors = new HashMap<String, Array<Actor>>();
actionActors = new HashMap<Integer, Actor>();
//animations = new HashMap<String, Map<Actor, Action>>();
actorActionMap = new HashMap<Actor, Action>();
dirName = jsonFile.parent().toString();
if (!dirName.equals("")) {
dirName += File.separator;
}
String json = jsonFile.readString("utf-8");
Json jj = new Json();
jj.setIgnoreUnknownFields(true);
export = jj.fromJson(CCExport.class, json);
}
示例12: deserialize
import com.badlogic.gdx.utils.Json; //導入方法依賴的package包/類
/**
* Transforms {@code Map<String,Object>} to {@code T object}.
* <p>
* Transformation flow is as follow:
* <ul>
* <li>Transform {@code map} to Json string by {@link Json#toJson(Object)}
* <li>Transform Json string to POJO object by {@link Json#fromJson(Class, String)}
* </ul>
*
* @param map Map which we want to transform.
* @param wantedType Class type we want to get
* @param <T> Generic type of class we want to get. Needed if type we want have nested generic type.
* @return Deserialized object, may be null
*/
public static <T> T deserialize(Map<String, Object> map, Class<T> wantedType)
{
try {
String jsonString = new Json().toJson(map);
Json json = new Json();
json.setIgnoreUnknownFields(true);
return json.fromJson(wantedType, jsonString);
} catch (Exception e) {
return null;
}
}