本文整理汇总了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;
}
}