//iterate over class fields
for (PropertyDescriptor prop : props) {
Method writeMethod = prop.getWriteMethod();
Class<?> propertyType = prop.getPropertyType();
JSONWebService writeMethodConfig = writeMethod != null ? writeMethod.getAnnotation(JSONWebService.class) : null;
String expectedJSONPropName= (writeMethodConfig != null && !writeMethodConfig.name().isEmpty()) ? writeMethodConfig.name() : prop.getName();
// JOSN input contains specified property.
if (elements.containsKey(expectedJSONPropName)) {
Object value = elements.get(expectedJSONPropName);
if (writeMethod != null) {
if (writeMethodConfig != null
&& !writeMethodConfig.deserialize()) {
if(traceEnabled){
traceLog.info(String.format("Ignoring property %s due to deserialize set to false", expectedJSONPropName));
}
continue;
}
//use only public setters Bean property describer get only accessable setter.
// Bean getter always works on single property get. if (paramTypes.length == 1) {
try{
Class<?>[] paramTypes = writeMethod.getParameterTypes();
Type[] genericTypes = writeMethod.getGenericParameterTypes();
Object convertedValue = this.convert(paramTypes[0], genericTypes[0], value, writeMethodConfig, writeMethod);
writeMethod.invoke(object, convertedValue);
}catch(Throwable exp){
if(prop instanceof PublicFieldPropertyDescriptor){
((PublicFieldPropertyDescriptor)prop).setValue(object, value);
}
if(traceEnabled){
traceLog.warn(String.format("Exception while writing property \"%s\". Input %s. Expected type %s",
expectedJSONPropName, value, propertyType.getSimpleName()));
}
}
// }
} else if (prop.getReadMethod() != null && Collection.class.isAssignableFrom(propertyType)) {
try {
Method readMethod = prop.getReadMethod();
JSONWebService readMethodConfig = readMethod.getAnnotation(JSONWebService.class);
if(readMethodConfig == null || readMethodConfig.deserialize()){
// add configuration
Collection<Object> objectList = (Collection<Object>) readMethod.invoke(object);
if(objectList != null){
if(traceEnabled){
traceLog.info(String.format("Only list read method found for property %s adding new values to existing collection. " +