本文整理匯總了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);
}