/*
* Step 5.10.2.4.2: Read property value from object. If value null attempt to get it from default value.
*/
try{
Field declaredField = getDeclaredField(clazz,name);
XmlElement xmlElm = declaredField.getAnnotation(XmlElement.class);
if(xmlElm != null){
if(!xmlElm.defaultValue().equals(NULL) && isJSONPrimitive(propertyType)){
value = xmlElm.defaultValue();
} else if(!xmlElm.nillable() && createDefaultOnNonNullable){
if(!isJSONPrimitive(propertyType)){
if(!stackNillableInstances.contains(propertyType)){
stackNillableInstances.push(propertyType);
value = getNewInstance(propertyType);
hasData = this.add(name, value, null, hasData, property) || hasData;
stackNillableInstances.pop();
}
continue nextProperty;
}else{
// Primitive don't have any default WHAT TODO . E.g. Integer object can't be instantiated.
}
}
}
}catch(Throwable th){}
// Value still null
if(value == null && JSONCodec.excludeNullProperties && !this.metaDataMode){
continue nextProperty;
} else if(this.metaDataMode) {
// In meta data mode always get data via meta provider.
value = getMetaDataInstance(propertyType, accessor.getAnnotation(JSONWebService.class),
getDeclaredField(clazz,name));
}
}else if(this.metaDataMode && propertyType.isPrimitive()){
// Primitive meta data. In case like int value become 0. But it may be from default
value = getMetaDataInstance(propertyType, accessor.getAnnotation(JSONWebService.class),
getDeclaredField(clazz,name));
}
/*
* Step 5.10.2.4.3: read property custom config. If it is serializable continue process with specified name if any
*/
JSONWebService properyConfig = accessor.getAnnotation(JSONWebService.class);
if (properyConfig != null) {
if (!properyConfig.serialize())
continue;
else if (properyConfig.name().length() > 0)
name = properyConfig.name();
}else{
/*
* Step 5.10.2.4.4: JSON config not present. Then read XML configuration.
*/
try{
// XML annotation present at field level.
Field declaredField = getDeclaredField(clazz,name);
XmlElement xmlElm = declaredField.getAnnotation(XmlElement.class);
/*
* Step 5.10.2.4.5: If XML transient ignore property.
*/
if (declaredField.isAnnotationPresent(XmlMimeType.class)){
if(this.metaDataMode){
value = declaredField.getAnnotation(XmlMimeType.class).value();
}else{
Map<String,Object> attachment = new HashMap<String, Object>();;
attachment .put("name", name);
attachment.put("value", value);
attachment.put("mimeType",declaredField.getAnnotation(XmlMimeType.class).value());
attachments .add(attachment);
continue nextProperty;
}
} else if(xmlElm != null) {// MAjor hits are here
/*
* Step 5.10.2.4.4.2: Xml elements .
*/
if(!xmlElm.name().equals(XML_DEFAULT)){
name = xmlElm.name();
}
}else if(declaredField.isAnnotationPresent(XmlElements.class) && Collection.class.isAssignableFrom(declaredField.getType())
&& value instanceof Collection){
// XML choice list
/*