@Override public void write(Json json) { json.writeValue("currentLevelId", currentLevelId); json.writeValue("credits", credits); json.writeValue("highScores", highScores); json.writeValue("coon", coon); }
@Override public void write(Json json) { json.writeValue("previousFA", previousAnim); json.writeValue("responseText", responseText); json.writeValue("characterTurn", characterTurn); json.writeValue("characterName", characterName); super.write(json); }
@Override public void write(Json json) { json.writeValue(JsonKey.X, position.x); json.writeValue(JsonKey.Y, position.y); json.writeValue(JsonKey.Z, position.z); json.writeValue(JsonKey.YAW, eulerAngles.x); json.writeValue(JsonKey.PITCH, eulerAngles.y); json.writeValue(JsonKey.ROLL, eulerAngles.z); }
/** @param value May be null. */ public void writeValue(String name, Object value) { try { writer.name(name); } catch (IOException ex) { throw new SerializationException(ex); } if (value == null) writeValue(value, null, null); else writeValue(value, value.getClass(), null); }
@Override public void write(Json json) { json.writeValue("actorId", actorId); json.writeValue("ip", ip); json.writeValue("verb", verb); json.writeValue("target", target); json.writeValue("state", state); super.write(json); }
@Override public void write(Json json) { super.write(json); json.writeValue("path", walkingPath); json.writeValue("currentStep", currentStep); json.writeValue("speed", speed); json.writeValue( "walkCb", ActionCallbackSerialization.find(walkCb), walkCb == null ? null : String.class); }
@Override public void write(Json json, IntMap intMap, Class knownType) { json.writeObjectStart(); json.writeValue(VALUE_SIZE, intMap.size); json.writeArrayStart(VALUE_ENTRIES); for (IntMap.Entry entry : (IntMap.Entries<?>) intMap.entries()) { json.writeValue(String.valueOf(entry.key), entry.value, null); } json.writeArrayEnd(); json.writeObjectEnd(); }
/** @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 = typeToFields.get(type); if (fields == null) fields = cacheFields(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 (IllegalAccessException 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; } }
@Override public void write(Json json, PolygonCentroid object, Class knownType) { json.writeObjectStart(); json.writeValue("x", object.x); json.writeValue("y", object.y); json.writeObjectEnd(); }
public <E> void write( Json json, Iterable<E> entries, Function<E, ?> getKey, Function<E, ?> getValue) { json.writeArrayStart(name); entries.forEach( entry -> { json.writeObjectStart(); json.writeValue("key", getKey.apply(entry), map.key()); json.writeValue("value", getValue.apply(entry), map.value()); json.writeObjectEnd(); }); json.writeArrayEnd(); }
/** * @param value May be null. * @param knownType May be null if the type is unknown. * @param elementType May be null if the type is unknown. */ public void writeValue(String name, Object value, Class knownType, Class elementType) { try { writer.name(name); } catch (IOException ex) { throw new SerializationException(ex); } writeValue(value, knownType, elementType); }
/** * @param knownType May be null if the type is unknown. * @param elementType May be null if the type is unknown. */ public void toJson(Object object, Class knownType, Class elementType, Writer writer) { if (!(writer instanceof JsonWriter)) { writer = new JsonWriter(writer); } ((JsonWriter) writer).setOutputType(outputType); this.writer = (JsonWriter) writer; try { writeValue(object, knownType, elementType); } finally { this.writer = null; } }
/** * @param knownType May be null if the type is unknown. * @param elementType May be null if the type is unknown. */ public void toJson(Object object, Class knownType, Class elementType, Writer writer) { setWriter(writer); try { writeValue(object, knownType, elementType); } finally { try { this.writer.close(); } catch (Exception ignored) { } this.writer = null; } }
@Override public void write(Json json, TreeJson label, Class arg2) { json.writeObjectStart(); json.writeValue("class", label.getClass().getName()); json.writeValue("name", label.getName()); json.writeValue("x", label.getX()); json.writeValue("y", label.getY()); json.writeValue("width", label.getWidth()); json.writeValue("height", label.getHeight()); json.writeValue("color", label.getColor().toString()); json.writeObjectEnd(); }
public void writeFields(Object object) { Class type = object.getClass(); Object[] defaultValues = getDefaultValues(type); ObjectMap<String, FieldMetadata> fields = typeToFields.get(type); if (fields == null) fields = cacheFields(type); int i = 0; for (FieldMetadata metadata : fields.values()) { Field field = metadata.field; try { Object value = field.get(object); if (defaultValues != null) { Object defaultValue = defaultValues[i++]; if (value == null && defaultValue == null) continue; if (value != null && defaultValue != null && value.equals(defaultValue)) continue; } if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")"); writer.name(field.getName()); writeValue(value, field.getType(), metadata.elementType); } catch (IllegalAccessException 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; } } }
@Override public void write(Json json) { json.writeValue("name", name); json.writeObjectStart("dir"); json.writeValue("x", dir.x); json.writeValue("y", dir.y); json.writeObjectEnd(); json.writeValue("speed", speed); json.writeObjectStart("bounds"); json.writeValue("x", bounds.x); json.writeValue("y", bounds.y); json.writeValue("width", bounds.width); json.writeValue("height", bounds.height); json.writeObjectEnd(); json.writeObjectStart("score"); score.write(json); json.writeObjectEnd(); }
@Override public void write(Json json) { json.writeValue("user_email", userEmail); json.writeValue("user_password", userPassword); }
/** * @param value May be null. * @param knownType May be null if the type is unknown. * @param elementType May be null if the type is unknown. */ public void writeValue(Object value, Class knownType, Class elementType) { try { if (value == null) { writer.value(null); return; } Class actualType = value.getClass(); if (actualType.isPrimitive() || actualType == String.class || actualType == Integer.class || actualType == Boolean.class || actualType == Float.class || actualType == Long.class || actualType == Double.class || actualType == Short.class || actualType == Byte.class || actualType == Character.class) { writer.value(value); return; } if (value instanceof Serializable) { writeObjectStart(actualType, knownType); ((Serializable) value).write(this); writeObjectEnd(); return; } Serializer serializer = classToSerializer.get(actualType); if (serializer != null) { serializer.write(this, value, knownType); return; } if (value instanceof Array) { if (knownType != null && actualType != knownType) throw new SerializationException( "Serialization of an Array other than the known type is not supported.\n" + "Known type: " + knownType + "\nActual type: " + actualType); writeArrayStart(); Array array = (Array) value; for (int i = 0, n = array.size; i < n; i++) writeValue(array.get(i), elementType, null); writeArrayEnd(); return; } if (value instanceof Collection) { if (knownType != null && actualType != knownType && actualType != ArrayList.class) throw new SerializationException( "Serialization of a Collection other than the known type is not supported.\n" + "Known type: " + knownType + "\nActual type: " + actualType); writeArrayStart(); for (Object item : (Collection) value) writeValue(item, elementType, null); writeArrayEnd(); return; } if (actualType.isArray()) { if (elementType == null) elementType = actualType.getComponentType(); int length = java.lang.reflect.Array.getLength(value); writeArrayStart(); for (int i = 0; i < length; i++) writeValue(java.lang.reflect.Array.get(value, i), elementType, null); writeArrayEnd(); return; } if (value instanceof OrderedMap) { if (knownType == null) knownType = OrderedMap.class; writeObjectStart(actualType, knownType); OrderedMap map = (OrderedMap) value; for (Object key : map.orderedKeys()) { writer.name(convertToString(key)); writeValue(map.get(key), elementType, null); } writeObjectEnd(); return; } if (value instanceof ArrayMap) { if (knownType == null) knownType = ArrayMap.class; writeObjectStart(actualType, knownType); ArrayMap map = (ArrayMap) value; for (int i = 0, n = map.size; i < n; i++) { writer.name(convertToString(map.keys[i])); writeValue(map.values[i], elementType, null); } writeObjectEnd(); return; } if (value instanceof ObjectMap) { if (knownType == null) knownType = OrderedMap.class; writeObjectStart(actualType, knownType); for (Entry entry : ((ObjectMap<?, ?>) value).entries()) { writer.name(convertToString(entry.key)); writeValue(entry.value, elementType, null); } writeObjectEnd(); return; } if (value instanceof Map) { if (knownType == null) knownType = OrderedMap.class; writeObjectStart(actualType, knownType); for (Map.Entry entry : ((Map<?, ?>) value).entrySet()) { writer.name(convertToString(entry.getKey())); writeValue(entry.getValue(), elementType, null); } writeObjectEnd(); return; } if (actualType.isEnum()) { writer.value(value); return; } writeObjectStart(actualType, knownType); writeFields(value); writeObjectEnd(); } catch (IOException ex) { throw new SerializationException(ex); } }
/** * @param value May be null. * @param knownType May be null if the type is unknown. */ public void writeValue(Object value, Class knownType) { writeValue(value, knownType, null); }
/** @param value May be null. */ public void writeValue(Object value) { if (value == null) writeValue(value, null, null); else writeValue(value, value.getClass(), null); }
@Override public void write(Json json) { json.writeValue("layers", layers); json.writeValue("id", id); json.writeValue("state", state, state == null ? null : state.getClass()); json.writeValue("verbs", verbManager); json.writeValue("actors", actors); json.writeValue("player", player); json.writeValue("backgroundAtlas", backgroundAtlas); json.writeValue("backgroundRegionId", backgroundRegionId); json.writeValue("lightMapAtlas", lightMapAtlas); json.writeValue("lightMapRegionId", lightMapRegionId); json.writeValue("musicFilename", musicFilename); json.writeValue("loopMusic", loopMusic); json.writeValue("initialMusicDelay", initialMusicDelay); json.writeValue("repeatMusicDelay", repeatMusicDelay); json.writeValue("isPlaying", music != null && music.isPlaying()); json.writeValue("musicPos", music != null && music.isPlaying() ? music.getPosition() : 0f); json.writeValue("camera", camera); json.writeValue( "followActor", followActor == null ? null : followActor.getId(), followActor == null ? null : String.class); json.writeValue("depthVector", depthVector); json.writeValue( "polygonalNavGraph", polygonalNavGraph, polygonalNavGraph == null ? null : PolygonalNavGraph.class); }
/** @param value May be null. */ public void writeValue(Object value) { writeValue(value, value.getClass(), null); }
@Override public void write(final Json json) { json.writeValue("leaves", leaves); }
@Override public void write(Json json) { json.writeValue("Width", width); json.writeValue("Height", height); json.writeValue("Keys", keys, ObjectMap.class); }