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

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

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

Json.getFields介绍

暂无

代码示例

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

/** Sets the type of elements in a collection. When the element type is known, the class for each element in the collection
 * does not need to be written unless different from the element type. */
public void setElementType (Class type, String fieldName, Class elementType) {
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  metadata.elementType = elementType;
}

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

/** Sets the type of elements in a collection. When the element type is known, the class for each element in the collection
 * does not need to be written unless different from the element type. */
public void setElementType (Class type, String fieldName, Class elementType) {
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  metadata.elementType = elementType;
}

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

/** @param elementType May be null if the type is unknown. */
public void readField (Object object, String fieldName, String jsonName, Class elementType, JsonValue jsonMap) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  Field field = metadata.field;
  if (elementType == null) elementType = metadata.elementType;
  readField(object, field, jsonName, elementType, jsonMap);
}

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

/** @param elementType May be null if the type is unknown. */
public void readField (Object object, String fieldName, String jsonName, Class elementType, JsonValue jsonMap) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  Field field = metadata.field;
  if (elementType == null) elementType = metadata.elementType;
  readField(object, field, jsonName, elementType, jsonMap);
}

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

/** Each field on the <code>to</code> object is set to the value for the field with the same name on the <code>from</code>
 * object. The <code>to</code> object must have at least all the fields of the <code>from</code> object with the same name and
 * type. */
public void copyFields (Object from, Object to) {
  ObjectMap<String, FieldMetadata> toFields = getFields(from.getClass());
  for (ObjectMap.Entry<String, FieldMetadata> entry: getFields(from.getClass())) {
    FieldMetadata toField = toFields.get(entry.key);
    Field fromField = entry.value.field;
    if (toField == null) throw new SerializationException("To object is missing field" + entry.key);
    try {
      toField.field.set(to, fromField.get(from));
    } catch (ReflectionException ex) {
      throw new SerializationException("Error copying field: " + fromField.getName(), ex);
    }
  }
}

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

/** Each field on the <code>to</code> object is set to the value for the field with the same name on the <code>from</code>
 * object. The <code>to</code> object must have at least all the fields of the <code>from</code> object with the same name and
 * type. */
public void copyFields (Object from, Object to) {
  ObjectMap<String, FieldMetadata> toFields = getFields(from.getClass());
  for (ObjectMap.Entry<String, FieldMetadata> entry: getFields(from.getClass())) {
    FieldMetadata toField = toFields.get(entry.key);
    Field fromField = entry.value.field;
    if (toField == null) throw new SerializationException("To object is missing field" + entry.key);
    try {
      toField.field.set(to, fromField.get(from));
    } catch (ReflectionException ex) {
      throw new SerializationException("Error copying field: " + fromField.getName(), ex);
    }
  }
}

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

/** Writes the specified field to the current JSON object.
 * @param elementType May be null if the type is unknown. */
public void writeField (Object object, String fieldName, String jsonName, Class elementType) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  Field field = metadata.field;
  if (elementType == null) elementType = metadata.elementType;
  try {
    if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")");
    writer.name(jsonName);
    writeValue(field.get(object), field.getType(), elementType);
  } catch (ReflectionException ex) {
    throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
  } catch (SerializationException ex) {
    ex.addTrace(field + " (" + type.getName() + ")");
    throw ex;
  } catch (Exception runtimeEx) {
    SerializationException ex = new SerializationException(runtimeEx);
    ex.addTrace(field + " (" + type.getName() + ")");
    throw ex;
  }
}

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

/** Writes the specified field to the current JSON object.
 * @param elementType May be null if the type is unknown. */
public void writeField (Object object, String fieldName, String jsonName, Class elementType) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  Field field = metadata.field;
  if (elementType == null) elementType = metadata.elementType;
  try {
    if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")");
    writer.name(jsonName);
    writeValue(field.get(object), field.getType(), elementType);
  } catch (ReflectionException ex) {
    throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
  } catch (SerializationException ex) {
    ex.addTrace(field + " (" + type.getName() + ")");
    throw ex;
  } catch (Exception runtimeEx) {
    SerializationException ex = new SerializationException(runtimeEx);
    ex.addTrace(field + " (" + type.getName() + ")");
    throw ex;
  }
}

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

OrderedMap<String, FieldMetadata> fields = getFields(type);
int i = 0;
for (FieldMetadata metadata : new OrderedMapValues<FieldMetadata>(fields)) {

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

OrderedMap<String, FieldMetadata> fields = getFields(type);
int i = 0;
for (FieldMetadata metadata : new OrderedMapValues<FieldMetadata>(fields)) {

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

public void readFields (Object object, JsonValue jsonMap) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  for (JsonValue child = jsonMap.child; child != null; child = child.next) {
    FieldMetadata metadata = fields.get(child.name().replace(" ", "_"));

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

public void readFields (Object object, JsonValue jsonMap) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  for (JsonValue child = jsonMap.child; child != null; child = child.next) {
    FieldMetadata metadata = fields.get(child.name().replace(" ", "_"));

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

ObjectMap<String, FieldMetadata> fields = getFields(type);
Object[] values = new Object[fields.size];
classToDefaultValues.put(type, values);

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

ObjectMap<String, FieldMetadata> fields = getFields(type);
Object[] values = new Object[fields.size];
classToDefaultValues.put(type, values);

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

/** Sets the type of elements in a collection. When the element type is known, the class for each element in the collection
 * does not need to be written unless different from the element type. */
public void setElementType (Class type, String fieldName, Class elementType) {
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  metadata.elementType = elementType;
}

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

/** @param elementType May be null if the type is unknown. */
public void readField (Object object, String fieldName, String jsonName, Class elementType, JsonValue jsonMap) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  Field field = metadata.field;
  if (elementType == null) elementType = metadata.elementType;
  readField(object, field, jsonName, elementType, jsonMap);
}

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

/** Each field on the <code>to</code> object is set to the value for the field with the same name on the <code>from</code>
 * object. The <code>to</code> object must have at least all the fields of the <code>from</code> object with the same name and
 * type. */
public void copyFields (Object from, Object to) {
  ObjectMap<String, FieldMetadata> toFields = getFields(from.getClass());
  for (ObjectMap.Entry<String, FieldMetadata> entry: getFields(from.getClass())) {
    FieldMetadata toField = toFields.get(entry.key);
    Field fromField = entry.value.field;
    if (toField == null) throw new SerializationException("To object is missing field" + entry.key);
    try {
      toField.field.set(to, fromField.get(from));
    } catch (ReflectionException ex) {
      throw new SerializationException("Error copying field: " + fromField.getName(), ex);
    }
  }
}

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

/** Writes the specified field to the current JSON object.
 * @param elementType May be null if the type is unknown. */
public void writeField (Object object, String fieldName, String jsonName, Class elementType) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  FieldMetadata metadata = fields.get(fieldName);
  if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
  Field field = metadata.field;
  if (elementType == null) elementType = metadata.elementType;
  try {
    if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")");
    writer.name(jsonName);
    writeValue(field.get(object), field.getType(), elementType);
  } catch (ReflectionException ex) {
    throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
  } catch (SerializationException ex) {
    ex.addTrace(field + " (" + type.getName() + ")");
    throw ex;
  } catch (Exception runtimeEx) {
    SerializationException ex = new SerializationException(runtimeEx);
    ex.addTrace(field + " (" + type.getName() + ")");
    throw ex;
  }
}

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

public void readFields (Object object, JsonValue jsonMap) {
  Class type = object.getClass();
  ObjectMap<String, FieldMetadata> fields = getFields(type);
  for (JsonValue child = jsonMap.child; child != null; child = child.next) {
    FieldMetadata metadata = fields.get(child.name().replace(" ", "_"));

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

ObjectMap<String, FieldMetadata> fields = getFields(type);
Object[] values = new Object[fields.size];
classToDefaultValues.put(type, values);

相关文章