[
https://issues.apache.org/jira/browse/CAMEL-12260?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16367449#comment-16367449
]
ASF GitHub Bot commented on CAMEL-12260:
----------------------------------------
oscerd closed pull request #2228: CAMEL-12260: Default value for String field
results is null for CSV/Bindy
URL: https://github.com/apache/camel/pull/2228
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
index f0bc611708c..fd1c1490209 100644
---
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
@@ -79,6 +79,7 @@ public void initModel() throws Exception {
*
* @param root
*/
+ @SuppressWarnings("rawtypes")
private void loadModels(Class<?> root) {
models.add(root);
modelClassNames.add(root.getName());
@@ -231,6 +232,8 @@ public static Object getDefaultValueForPrimitive(Class<?>
clazz) throws Exceptio
return Character.MIN_VALUE;
} else if (clazz == boolean.class) {
return false;
+ } else if (clazz == String.class) {
+ return "";
} else {
return null;
}
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
index 5585abb5cd2..d5c9799bd88 100644
---
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
@@ -313,6 +313,7 @@ private boolean
isTrimmingNeededAndEnabled(BindyFixedLengthFactory factory, Stri
return factory.isIgnoreTrailingChars() && myLine.length() >
factory.recordLength();
}
+ @SuppressWarnings("unused")
private String rightPad(String myLine, int length) {
return String.format("%1$-" + length + "s", myLine);
}
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
index bee2c7b1659..144429f704f 100644
---
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
@@ -61,7 +61,7 @@ public void
testUnmarshallCsvRecordFieldStartingWithSeparatorChar() throws Excep
assertEquals(BigDecimal.valueOf(3), row.getNumber());
row =
mockEndPoint.getExchanges().get(3).getIn().getBody(BindyCsvRowFormat.class);
- assertEquals(null, row.getFirstField());
+ assertEquals("", row.getFirstField());
assertEquals(",val2,", row.getSecondField());
assertEquals(BigDecimal.valueOf(4), row.getNumber());
}
@@ -79,6 +79,7 @@ public void configure() throws Exception {
}
//from https://issues.apache.org/jira/browse/CAMEL-11065
+ @SuppressWarnings("serial")
@CsvRecord(separator = ",", quote = "'")
public static class BindyCsvRowFormat implements Serializable {
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
index 277c26c0b98..d507c3f2e99 100644
---
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
@@ -25,6 +25,7 @@
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
import org.apache.camel.dataformat.bindy.format.FormatException;
import org.apache.camel.dataformat.bindy.model.simple.oneclass.Order;
import org.apache.camel.processor.interceptor.Tracer;
@@ -127,8 +128,13 @@ public void testUnMarshallMessageWithMissingFields()
throws Exception {
assertNotNull(orders);
// As the @DataField defines a default value for the firstName, the
- // value might not be empty
+ // value might not be empty and equal to defaultValue property
+ // inside @DataField annotation
assertFalse(orders.get(0).getFirstName().isEmpty());
+ assertEquals("Joe", orders.get(0).getFirstName());
+
+ // Check default String value set to empty ("") for the skipped
clientNr field
+ assertEquals("", orders.get(0).getClientNr());
}
public static class ContextConfig extends RouteBuilder {
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/BindyPaddingAndTrimmingTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/BindyPaddingAndTrimmingTest.java
index 9e3e1740853..8ba38f9ddb6 100644
---
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/BindyPaddingAndTrimmingTest.java
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/BindyPaddingAndTrimmingTest.java
@@ -26,8 +26,6 @@
import org.hamcrest.core.Is;
import org.junit.Test;
-import static org.hamcrest.core.IsNull.nullValue;
-
public class BindyPaddingAndTrimmingTest extends CamelTestSupport {
private static final String URI_DIRECT_UNMARSHAL = "direct:unmarshall";
@@ -56,7 +54,7 @@ public void testUnmarshal() throws Exception {
unmarhsalResult.assertIsSatisfied();
MyBindyModel myBindyModel =
unmarhsalResult.getReceivedExchanges().get(0).getIn().getBody(MyBindyModel.class);
assertEquals("foo ", myBindyModel.foo);
- assertThat(myBindyModel.bar, Is.is(nullValue()));
+ assertThat(myBindyModel.bar, Is.is(""));
}
@Test
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Default value for String field results in null for CSV / Bindy
> --------------------------------------------------------------
>
> Key: CAMEL-12260
> URL: https://issues.apache.org/jira/browse/CAMEL-12260
> Project: Camel
> Issue Type: Bug
> Components: camel-bindy
> Affects Versions: 2.20.2
> Reporter: Pauli Borodulin
> Assignee: Dmitry Volodin
> Priority: Minor
> Fix For: 2.21.0
>
>
> **CAMEL-5018 added "support the set the default value on the field of bindy
> CVS", which is nice, but the default value is useless for Strings, because
> BindyCSVFactory turns the empty value to null even when defaultValue = "", see
> [https://github.com/apache/camel/blob/camel-2.20.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java#L230]
> and
> [https://github.com/apache/camel/blob/camel-2.20.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java#L234]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)