骆驼Bindy:对于布尔字段设置默认值 [英] Camel Bindy: set default value for boolean field

查看:358
本文介绍了骆驼Bindy:对于布尔字段设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Bindy到地图csv文件数据到一个给定的模型类。这整个过程中工作正常,但布尔字段的默认值。此字段是不是在进一步处理模型类csv文件的一部分,而且是必要的。我已经默认值设置为真正,但是这将是的忽略的和现场正在总是被设置为如果我跑骆驼的路线。

I'm using Bindy to a map csv file data to a given model class. This whole process works fine, except the default value of the boolean field. This field is not part of the csv file, but necessary in the model class for further processes. I have set the default value to true, but this will be "ignored" and the field is currently always set to false if I run the camel route.

这是我的模型类的一个片段:

This is a snippet of my model class:

@CsvRecord(separator = " ", skipFirstLine = false)
public class MyModel {

  // ... more data fields

  @DataField(pos = 8, defaultValue = "true")
  public boolean approved;

设置defaultValue 需要一个字符串值,所以我不能将其设置为 Boolean.TRUE 。我已经尝试过像 TRUE 其他值和 1 ,没有运气。

defaultValue expects a string value so I can't set it to Boolean.TRUE. I already tried other values like TRUE, yes, y and 1 with no luck.

的<一个源href=\"http://camel.apache.org/maven/camel-2.11.0/camel-bindy/apidocs/src-html/org/apache/camel/dataformat/bindy/BindyCsvFactory.html\"相对=nofollow> BindyCsvFactory 说,类格式是用来设置默认值,但似乎它不能处理的布尔字段,并使用布尔代替,这是

The source of BindyCsvFactory says that the class Format is used to set the default value, but it seems that it can't handle boolean fields and uses the default of boolean instead and this is false.

目前的区域设置使用此命令设置为EN_US:

Currently the locale is set to en_Us using this command:

  BindyCsvDataFormat format = new BindyCsvDataFormat("[model package]");
  format.setLocale("en_US");

..如果它帮助。

.. if it helps.

TL:博士。我怎么一个布尔字段的默认值设置为真正在Bindy管理模型类

tl:dr .. how do I set the default value of a boolean field to true in a Bindy managed model class?

非常感谢。

推荐答案

您不能。如果你看一下格式工厂code(<一个href=\"http://camel.apache.org/maven/camel-2.11.0/camel-bindy/apidocs/src-html/org/apache/camel/dataformat/bindy/FormatFactory.html\" rel=\"nofollow\">http://camel.apache.org/maven/camel-2.11.0/camel-bindy/apidocs/src-html/org/apache/camel/dataformat/bindy/FormatFactory.html)你可以看到,它不支持布尔值。

You can't. If you have a look at the FormatFactory code (http://camel.apache.org/maven/camel-2.11.0/camel-bindy/apidocs/src-html/org/apache/camel/dataformat/bindy/FormatFactory.html) you can see that it doesn't support booleans.

它看起来像你的选择是要么

It looks like your choices are either


  • 取出@DataField注解,只是初始化与布尔
    =核定真正的公共布尔。你必须重新添加在以后一旦批准字段添加到输入文件。

  • 读取列作为字符串或整数并转换为布尔在code。

  • Remove the @DataField annotation and just initialise the boolean with public boolean approved = true. You'll have to add it back in later once the approved field is added to the input file.
  • Read the column as a string or integer and convert to a boolean in your code.

这篇关于骆驼Bindy:对于布尔字段设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆