本文整理汇总了Java中com.badlogic.gdx.utils.Json.setTypeName方法的典型用法代码示例。如果您正苦于以下问题:Java Json.setTypeName方法的具体用法?Java Json.setTypeName怎么用?Java Json.setTypeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.Json
的用法示例。
在下文中一共展示了Json.setTypeName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}