/** 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; }
/** @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); }
/** @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); }
/** 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); } } }
/** 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); } } }
/** 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; } }
/** 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; } }
OrderedMap<String, FieldMetadata> fields = getFields(type); int i = 0; for (FieldMetadata metadata : new OrderedMapValues<FieldMetadata>(fields)) {
OrderedMap<String, FieldMetadata> fields = getFields(type); int i = 0; for (FieldMetadata metadata : new OrderedMapValues<FieldMetadata>(fields)) {
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(" ", "_"));
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(" ", "_"));
ObjectMap<String, FieldMetadata> fields = getFields(type); Object[] values = new Object[fields.size]; classToDefaultValues.put(type, values);
ObjectMap<String, FieldMetadata> fields = getFields(type); Object[] values = new Object[fields.size]; classToDefaultValues.put(type, values);
/** 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; }
/** @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); }
/** 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); } } }
/** 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; } }
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(" ", "_"));
ObjectMap<String, FieldMetadata> fields = getFields(type); Object[] values = new Object[fields.size]; classToDefaultValues.put(type, values);