public void TestJsonReserializationSuccess() { AFDataHolder dataToTest = new AFDataHolder(); dataToTest.addPropertyAndValue("name", "Pavel"); dataToTest.addPropertyAndValue("lastName", "Matyáš"); AFDataHolder innerClass = new AFDataHolder(); innerClass.setClassName("adress"); innerClass.addPropertyAndValue("Street", "Zikova"); dataToTest.addInnerClass(innerClass); BaseRestBuilder restBuilder = new JSONBuilder(); Object json = restBuilder.reselialize(dataToTest); Assert.IsNotNull(json); }
public override AFDataHolder reserialize() { AFDataHolder dataHolder = new AFDataHolder(); foreach (AFField field in getFields()) { Object data = field.getWidgetBuilder().getData(); //little workaroud to fit in server //TODO if ever this thing will be released delete this!! if (field.getFieldInfo().getWidgetType().Equals(SupportedWidgets.NUMBERDOUBLEFIELD)) { data = ((String) data).Replace(',', '.'); } String propertyName = field.getId(); // Based on dot notation determine road. Road is used to add object to its right place String[] roadTrace = propertyName.Split(new [] {"."}, StringSplitOptions.None); if (roadTrace.Length > 1) { AFDataHolder startPoint = dataHolder; for (int i = 0; i < roadTrace.Length; i++) { String roadPoint = roadTrace[i]; // If road end then add this property as inner propety if (i + 1 == roadTrace.Length) { startPoint.addPropertyAndValue(roadPoint, (String) data); } else { // Otherwise it will be inner class so add if doesn't exist continue. AFDataHolder roadHolder = startPoint.getInnerClassByKey(roadPoint); if (roadHolder == null) { roadHolder = new AFDataHolder(); roadHolder.setClassName(roadPoint); startPoint.addInnerClass(roadHolder); } // Set start point on current possition in tree startPoint = roadHolder; } } } else { dataHolder.addPropertyAndValue(propertyName, data.ToString()); } } return dataHolder; }
public override object reselialize(AFDataHolder componentData) { JsonObject json = new JsonObject(); foreach (String key in componentData.getPropertiesAndValues().Keys) { String value = componentData.getPropertiesAndValues()[key]; // Check if value is only empty string. if so then set to null, null value can be // re-mapped to object but this "" wont if (String.IsNullOrWhiteSpace(value)) { continue; } json.Add(key, JsonValue.CreateStringValue(value)); } foreach (String childKey in componentData.getInnerClasses().Keys) { AFDataHolder value = componentData.getInnerClasses()[childKey]; JsonObject jsonInnerClass = (JsonObject)reselialize(value); json.Add(childKey, jsonInnerClass); } return json; }
public void addInnerClass(AFDataHolder data) { innerClasses.Add(data.getClassName(), data); }
public override object reselialize(AFDataHolder componentData) { throw new NotImplementedException("Not supported in this version!"); }
public abstract object reselialize(AFDataHolder componentData);
/// <summary> /// Creates data from list item on given position which can be inserted to form. /// </summary> /// <param name="position">position of list item in list view</param> /// <returns> data of list item prepared to be inserted in form</returns> private AFDataHolder createFormDataFromList(int position) { AFDataHolder dataHolder = new AFDataHolder(); foreach (AFField field in getFields()) { String propertyName = field.getId(); Object data = rows[position][propertyName]; // Based on dot notation determine road. Road is used to add object to its right place String[] roadTrace = propertyName.Split(new [] {"."}, StringSplitOptions.None); if (roadTrace.Length > 1) { AFDataHolder startPoint = dataHolder; for (int i = 0; i < roadTrace.Length; i++) { String roadPoint = roadTrace[i]; // If road end then add this property as inner propety if (i + 1 == roadTrace.Length) { startPoint.addPropertyAndValue(roadPoint, (String) data); } else { // Otherwise it will be inner class so add if doesn't exist continue. AFDataHolder roadHolder = startPoint.getInnerClassByKey(roadPoint); if (roadHolder == null) { roadHolder = new AFDataHolder(); roadHolder.setClassName(roadPoint); startPoint.addInnerClass(roadHolder); } // Set start point on current possition in tree startPoint = roadHolder; } } } else { dataHolder.addPropertyAndValue(propertyName, (String) data); } } return dataHolder; }