Skip to content

Commit

Permalink
reasonably simple work-around + comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Groostav committed Jun 10, 2015
1 parent 377509a commit 4181020
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ protected Object convert(final Object parent, final Class<?> type, final Convert
final Object result;
String referenceAttrName = getMapper().aliasForSystemAttribute("reference");
String reference = referenceAttrName == null ? null : reader.getAttribute(referenceAttrName);
boolean keepReference = type != null && getMapper().isReferenceable(type);
boolean keepReference = type == null || getMapper().isReferenceable(type);
R refKey = reference == null ? null : getReferenceKey(reference);

if (reference == null && ! keepReference){
result = super.convert(parent, type, converter);
} else if (reference != null && ! keepReference) {
if (reference != null && ! keepReference) {
// found a reference but we've been told not to keep them
throw badReference(type, reference);
} else if(reference != null && ! values.containsKey(refKey)){
// found a reference but there is no entry for that reference (garbage path)
throw badReference(type, reference);
} else if (reference != null){
Object cache = values.get(getReferenceKey(reference));
} else if (reference == null && ! keepReference){
// dont have a reference and we're not supposed to keep them.
result = super.convert(parent, type, converter);
} else if (reference != null && values.containsKey(refKey)){
// have a reference and have the value for that reference
Object cache = values.get(refKey);
result = cache == NULL ? null : cache;
} else {
// dont have a reference, and this type is referenceable
final R currentReferenceKey = getCurrentReferenceKey();
parentStack.push(currentReferenceKey);
result = super.convert(parent, type, converter);
Expand All @@ -78,13 +86,11 @@ protected Object convert(final Object parent, final Class<?> type, final Convert
return result;
}

private ConversionException badReference(Class type, String reference) {

ConversionException ex = new ConversionException("Invalid reference");
ex.add("class", type == null ? "not available" : type.getCanonicalName());
ex.add("reference", reference);

return ex;
private ConversionException badReference(Class<?> type, String reference) {
ConversionException conversionException = new ConversionException("Invalid reference");
conversionException.set("class", type == null ? "not available" : type.getCanonicalName());
conversionException.set("reference", reference);
return conversionException;
}

protected abstract R getReferenceKey(String reference);
Expand Down

0 comments on commit 4181020

Please sign in to comment.