Skip to content

Commit

Permalink
CAMEL-7159 - search for Link-ed fields and add them to the model auto…
Browse files Browse the repository at this point in the history
…matically
  • Loading branch information
janstey committed Jan 31, 2014
1 parent 62ffa32 commit 8440e70
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -19,6 +19,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -31,6 +32,8 @@
import org.apache.camel.dataformat.bindy.BindyAbstractDataFormat;
import org.apache.camel.dataformat.bindy.BindyAbstractFactory;
import org.apache.camel.dataformat.bindy.BindyCsvFactory;
import org.apache.camel.dataformat.bindy.annotation.DataField;
import org.apache.camel.dataformat.bindy.annotation.Link;
import org.apache.camel.dataformat.bindy.util.ConverterUtils;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.spi.PackageScanClassResolver;
Expand Down Expand Up @@ -88,6 +91,16 @@ public void marshal(Exchange exchange, Object body, OutputStream outputStream) t
String name = model.getClass().getName();
Map<String, Object> row = new HashMap<String, Object>(1);
row.put(name, model);
// search for @Link-ed fields and add them to the model
for (Field field : model.getClass().getDeclaredFields()) {
Link linkField = field.getAnnotation(Link.class);
if (linkField != null) {
boolean accessible = field.isAccessible();
field.setAccessible(true);
row.put(field.getType().getName(), field.get(model));
field.setAccessible(accessible);
}
}
models.add(row);
}
}
Expand Down

0 comments on commit 8440e70

Please sign in to comment.