public void writeArrayEnd () { try { writer.pop(); } catch (IOException ex) { throw new SerializationException(ex); } }
public void writeType (Class type) { if (typeName == null) return; String className = getTag(type); if (className == null) className = type.getName(); try { writer.set(typeName, className); } catch (IOException ex) { throw new SerializationException(ex); } if (debug) System.out.println("Writing type: " + type.getName()); }
/** 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; }
/** 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; }
public JsonValue parse (InputStream input) { try { return parse(new InputStreamReader(input, "UTF-8")); } catch (IOException ex) { throw new SerializationException(ex); } finally { StreamUtils.closeQuietly(input); } }
public Element parse (InputStream input) { try { return parse(new InputStreamReader(input, "UTF-8")); } catch (IOException ex) { throw new SerializationException(ex); } finally { StreamUtils.closeQuietly(input); } }
public void writeArrayStart (String name) { try { writer.name(name); writer.array(); } catch (IOException ex) { throw new SerializationException(ex); } }
public void writeObjectStart (String name) { try { writer.name(name); } catch (IOException ex) { throw new SerializationException(ex); } writeObjectStart(); }
public void writeArrayStart (String name) { try { writer.name(name); writer.array(); } catch (IOException ex) { throw new SerializationException(ex); } }
public JsonValue parse (FileHandle file) { try { return parse(file.reader("UTF-8")); } catch (Exception ex) { throw new SerializationException("Error parsing file: " + file, ex); } }
/** Adds all resources in the specified skin JSON file. */ public void load (FileHandle skinFile) { try { getJsonLoader(skinFile).fromJson(Skin.class, skinFile); } catch (SerializationException ex) { throw new SerializationException("Error reading file: " + skinFile, ex); } }
@Override public JsonValue parse (FileHandle file) { try { return parse(file.read(8192)); } catch (Exception ex) { throw new SerializationException("Error parsing file: " + file, ex); } }
/** @param knownType May be null if the type is unknown. */ public void writeObjectStart (String name, Class actualType, Class knownType) { try { writer.name(name); } catch (IOException ex) { throw new SerializationException(ex); } writeObjectStart(actualType, knownType); }
/** Adds all resources in the specified skin JSON file. */ public void load (FileHandle skinFile) { try { getJsonLoader(skinFile).fromJson(Skin.class, skinFile); } catch (SerializationException ex) { throw new SerializationException("Error reading file: " + skinFile, ex); } }
/** @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); }
public Element parse (FileHandle file) { try { return parse(file.reader("UTF-8")); } catch (Exception ex) { throw new SerializationException("Error parsing file: " + file, ex); } }
/** @param type May be null if the type is unknown. * @return May be null. */ public <T> T fromJson (Class<T> type, FileHandle file) { try { return (T)readValue(type, null, new JsonReader().parse(file)); } catch (Exception ex) { throw new SerializationException("Error reading file: " + file, ex); } }
/** @param type May be null if the type is unknown. * @return May be null. */ public <T> T fromJson (Class<T> type, FileHandle file) { try { return (T)readValue(type, null, new JsonReader().parse(file)); } catch (Exception ex) { throw new SerializationException("Error reading file: " + file, ex); } }
/** @param type May be null if the type is unknown. * @param elementType May be null if the type is unknown. * @return May be null. */ public <T> T fromJson (Class<T> type, Class elementType, FileHandle file) { try { return (T)readValue(type, elementType, new JsonReader().parse(file)); } catch (Exception ex) { throw new SerializationException("Error reading file: " + file, ex); } }
public Skin read (Json json, JsonValue typeToValueMap, Class ignored) { for (JsonValue valueMap = typeToValueMap.child; valueMap != null; valueMap = valueMap.next) { try { Class type = json.getClass(valueMap.name()); if (type == null) type = ClassReflection.forName(valueMap.name()); readNamedObjects(json, type, valueMap); } catch (ReflectionException ex) { throw new SerializationException(ex); } } return skin; }