com.badlogic.gdx.utils.Json.setTypeName()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(1.5k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中com.badlogic.gdx.utils.Json.setTypeName()方法的一些代码示例,展示了Json.setTypeName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.setTypeName()方法的具体详情如下:
包路径:com.badlogic.gdx.utils.Json
类名称:Json
方法名:setTypeName

Json.setTypeName介绍

[英]Sets the name of the JSON field to store the Java class name or class tag when required to avoid ambiguity during deserialization. Set to null to never output this information, but be warned that deserialization may fail. Default is "class".
[中]设置JSON字段的名称,以在需要时存储Java类名或类标记,以避免反序列化过程中出现歧义。设置为null以从不输出此信息,但请注意反序列化可能会失败。默认值为“类”。

代码示例

代码示例来源:origin: libgdx/libgdx

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.");
  }
}

代码示例来源:origin: libgdx/libgdx

json.setTypeName(null);
json.setUsePrototypes(false);

代码示例来源:origin: libgdx/libgdx

json.setTypeName(null);
json.setUsePrototypes(false);

代码示例来源:origin: com.badlogicgames.gdx/gdx

json.setTypeName(null);
json.setUsePrototypes(false);

相关文章