- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下使用Camels Bindy的示例,但最终它会引发断言错误,因为bindy以错误的方式转换BigDecimal(使用逗号而不是点作为数字分隔符)。
这段代码有什么问题?
public class PurchaseOrderBindyTest extends TestCase {
@Test
public void testBindy() throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(createRoute());
context.start();
MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedBodiesReceived("Camel in Action,39.95,1\n");
PurchaseOrder order = new PurchaseOrder();
order.setAmount(1);
order.setPrice(new BigDecimal("39.95"));
order.setName("Camel in Action");
ProducerTemplate template = context.createProducerTemplate();
template.sendBody("direct:toCsv", order);
mock.assertIsSatisfied();
}
public RouteBuilder createRoute() {
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:toCsv")
.marshal().bindy(BindyType.Csv, "camelinaction.bindy")
.to("mock:result");
}
};
}
}
型号
@CsvRecord(separator = ",", crlf = "UNIX")
public class PurchaseOrder {
@DataField(pos = 1)
private String name;
@DataField(pos = 2, precision = 2)
private BigDecimal price;
@DataField(pos = 3)
private int amount;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
断言错误
java.lang.AssertionError: mock://result Body of message: 0. Expected: <Camel in Action,39.95,1
> but was: <Camel in Action.39,95.1
>
最佳答案
我的测试通过了,没有任何问题。有趣的是,在你的例子中,“.”和“,”似乎颠倒了。
Camel 使用 java.text.DecimalFormat
类来确定区域设置,如下所示:
Locale def = Locale.getDefault(Locale.Category.FORMAT);
您可以按如下方式重置区域设置默认值:
Locale.setDefault(new Locale ("en", "US"));
如果您不想重置默认区域设置,可以按如下方式设置区域设置:
BindyCsvDataFormat bindy = new BindyCsvDataFormat(PurchaseOrder.class);
bindy.setLocale(Locale.US.getCountry());
from("direct:toCsv")
.marshal(bindy)
...
在这种情况下,Camel 会重置 AbstractNumberFormat
中的十进制格式符号,如下所示:
if (locale != null) {
this.format.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(locale));
}
关于java - Camel Bindy 不适本地转换 BigDecimal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26828777/
我正在从 CSV 文件中读取日期值,该值是“21/08/2009”。Bindy 在解析此数据时给我一个错误,如下所示: org.apache.camel.dataformat.bindy.format
我有以下使用Camels Bindy的示例,但最终它会引发断言错误,因为bindy以错误的方式转换BigDecimal(使用逗号而不是点作为数字分隔符)。 这段代码有什么问题? public clas
我正在使用带有 bindy (2.16.0) 的 camel 来解析 csv 文件。该文件包含页眉和页脚。两者都用作元数据来描述所有其他记录的公共(public)数据。 (客户定义,所以我无法更改 C
您好,我在将 java 对象导出到 Camel 中的 CSV 文件时遇到问题。假设如果我有一个名为 Student 的 java 对象, @CsvRecord(separator=",") publi
我有以下路线: from("direct:abc") // read the file .split(body().tokenize("\n", 3, false))
目前我可以使用 camel Bindy 从 POJO 生成平面文件,但无法将页眉和页脚添加到完整文件。 但是当我尝试向文件添加页眉/页脚时,它会添加到每条记录,但我需要将单个页眉/页脚添加到整个文件而
我正在使用 Apache Camel Bindy 处理不同数据模型的 csv 文件。例如文件一是数据模型,文件二是数据模型二。在 Camel route ,我将 BindyCsvDataFormat
我需要动态创建camel-bindy端点来编码输入。下面是示例代码: --> 我需要将交换传递到等效端点,而不是解码标签,但出现错误“无法找到名称为bindy
我正在使用 Camel Bindy 处理从第三方公司收到的 csv 文件。 在 csv 中,他们使用扩展 ascii 表中的分隔符:“\u00a4”(十进制代码 164)。 我尝试像这样设置bindy
我有一个平面文件,需要捕获其中的每一行并将其解码到 POJO 中。我正在使用 Camel 和 Bindy 并利用 Splitter EIP。由于某种原因,我无法在解码完成后检查 POJO(使用处理器)
我有两个类 CommonRequest 和 AccountRequest @FixedLengthRecord(paddingChar=' ',ignoreTrailingChars=true) pu
我需要能够将以下 CSV 转换为对象。Bindy 可以做到这一点吗? H,header1,01/01/2012 D,test11,1.00,10.00 D,test12,2.00,20.00 D,te
我的问题是我的平面文件中有两个不同的位置,带有“|”分离的字符串。位置2和3参见说明。我想生成 xml,并将两个描述附加到一个描述中,并返回一个包含两个描述的 DESC 标记。 输入源: UN|2.1
我编写了一个简单的方法来读取 CSV 文件并将其保存在 JSON 格式的新文件中。 当我尝试拆分和流式传输正文时,解码中断并显示“.IllegalArgumentException:CSV 中没有定义
我是一名优秀的程序员,十分优秀!