GithubHelp home page GithubHelp logo

mygreen / super-csv-annotation Goto Github PK

View Code? Open in Web Editor NEW
30.0 30.0 7.0 24.16 MB

'Super CSV' extention library for annotation

License: Apache License 2.0

Java 99.32% Batchfile 0.07% Makefile 0.02% JavaScript 0.04% CSS 0.03% HTML 0.07% Python 0.41% Shell 0.03%
annotations csv-annotation java supercsv

super-csv-annotation's People

Contributors

mygreen avatar shikazuki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

super-csv-annotation's Issues

CsvAnnotationBeanParser duplicates mappings

If bean column values are public, they are returned by both getFields() and getDeclaredFields(). Therefore, all public field mappings are added twice and validatePosition() failes with duplicated positions.

Instead, use getDeclaredFields() which should get you everything, including public fields. There is no reason to call both.

メッセージのUTF-8化

ResourceBundleMessageResolver を使って、propertiesファイルを読み込むときに、asciiコードに変換しているファイルを前提としているが、UTF-8で変換なしで取り込めるようにする。

BeanValidation2.0の対応

BeanValidation2.0(JSR-380)がリリースされたので対応を行う。

  • 基本的に、追加されたアノテーションに対するメッセージの追加。
  • java.timeクラスとして、OffsetDateTime/OffsetTime/Year/YearMonth/MonthDay に新たに対応する。
  • Joda-Timeのクラスとして、 YearMonth/MonthDay に新たに対応。

@CsvColumn label attribute purpose?

If the label attribute is not specified, the field name is used as the label. If the label attribute IS specified then SuperCSV looks for a getter/setter with that label name. If those getter/setter methods are created, there is no need for the label attribute since the getter/setter encapsulates the field anyway and the actual field could be named anything. What is the point of the label attribute if not to allow a column to be mapped to a field named something else? Getter/setter methods should be generated automatically based on annotations instead of allowing SuperCSV to look for missing accessor/mutator.

ラベルでカラム指定し、該当ラベルがヘッダに存在しない場合のExceptionについて

ライブラリ使わせていただいてます。
ラベルによるカラムマッピングで一点お願いがあるのですが、

    @CsvColumn(label="生年月日")
    @CsvDateTimeFormat(pattern="uuuu/MM/dd")
    private LocalDate birthday;

↑のようにラベルのみでカラム指定して、そのラベルと一致するヘッダが無いCSVを読み込んだ場合に、numberが0扱いになってしまうためSuperCsvInvalidAnnotationExceptionが発行されてしまいます。
アノテーションの付け方が悪いようなエラー内容になっていますが、どちらかといえばユーザ操作の問題かと思いますので、ヘッダのバリデーションチェック関連のExceptionに変更できないでしょうか?

↓Exception発行箇所は以下です。(複数見つからなかった場合は0の重複、一つの場合は1以上を指定)

if(!duplicatedNumbers.isEmpty()) {
// 重複している 属性 numberが存在する場合
throw new SuperCsvInvalidAnnotationException(MessageBuilder.create("anno.attr.duplicated")
.var("property", beanType.getName())
.varWithAnno("anno", CsvColumn.class)
.var("attrName", "number")
.var("attrValues", duplicatedNumbers)
.format());
}

if(minColumnNumber <= 0) {
throw new SuperCsvInvalidAnnotationException(MessageBuilder.create("anno.attr.min")
.var("property", beanType.getName())
.varWithAnno("anno", CsvColumn.class)
.var("attrName", "number")
.var("attrValue", minColumnNumber)
.var("min", 1)
.format());

fail load ResourceBundleMessageResolver.

java.lang.ExceptionInInitializerError
at org.supercsv.ext.localization.MessageConverter.(MessageConverter.java:23)
at org.supercsv.ext.CsvAnnotationBeanWriterTest.testRead3(CsvAnnotationBeanWriterTest.java:265)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.util.MissingResourceException: Can't find bundle for base name org/supercsv/ext/SuperCSVMessages, locale ja_JP
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at org.supercsv.ext.localization.ResourceBundleMessageResolver.(ResourceBundleMessageResolver.java:37)
at org.supercsv.ext.localization.ResourceBundleMessageResolver.(ResourceBundleMessageResolver.java:33)
... 26 more

ReplacedWordProvider のメソッドの戻り値のReplacedWordを内部クラスにする

インタフェース ReplacedWordProvoder のメソッド getReplacedWords の戻り値のReplacedWordを内部クラスにする。
CellProcessorの WordReplaceなどと間際らしいため。

// 変更前
@FunctionalInterface
public interface ReplacedWordProvider {
    
    Collection<ReplacedWord> getReplacedWords(FieldAccessor field);
    
}
// 変更後
@FunctionalInterface
public interface ReplacedWordProvider {
    
    public static class Word {
          private String word;
          private String replacement;

    }

    Collection<Word> getReplacedWords(FieldAccessor field);
    
}

CsvRegexReplaceを使用した部分一致の置換が行えない

概要

CsvRegexReplaceのアノテーションを使用して正規表現に該当する任意の文字列を複数置換することができません。

修正案

final Matcher matcher = pattern.matcher(value.toString());
if(matcher.matches()) {
final String result = matcher.replaceAll(replacement);
return next.execute(result, context);
}
return next.execute(value, context);

matcher.matches()を使用すると完全一致の比較になってしまいます。
部分一致させてmatcher.replacheAll()を呼ぶ場合、matcher.find()が適切かと思います。

または、CsvRegexReplaceはCsvRegexReplaceFirstとして、CsvRegexReplaceAllとして作成したほうが良いでしょうか?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.