我有这样的对象:
@CsvDataType()
public class MyCsvDto implements Serializable {
@CsvField(pos = 1)
private String str1;
@CsvField(pos = 4)
private String str4;
@CsvField(pos = 3)
private String str3;
@CsvField(pos = 2)
private String str2;
}
如果其中一个字段包含值:
"{"792":{"cust":"\n"},"104":{"firmMnemonic":"FSWB","houseAccountNum":104,"branchCode":"AL","floorBrokerNum":"781","cust":"\n"},"264":{"firmMnemonic":"FMST","houseAccountNum":264,"floorBrokerNum":"334","cust":"\n"}}"
结果csv看起来像这样:
"{""792"":{""firmMnemonic"":""AAAA"",""houseAccountNum"":111,""houseSuffix"":null,""branchCode"":""A111"",""branchSeqno"":null,""floorBrokerNum"":""A111"",""secondaryFloorBrokerNum"":null,""billingIndicator"":null,""cust"":""\n"",""cmta"":null,""supplementaryInfo"":null,""allOrNone"":null,""houseAccountInfo"":""111""},""104"":{""firmMnemonic"":""FSWB"",""houseAccountNum"":104,""houseSuffix"":null,""branchCode"":""AL"",""branchSeqno"":null,""floorBrokerNum"":""A111"",""secondaryFloorBrokerNum"":null,""billingIndicator"":null,""cust"":""\n"",""cmta"":null,""supplementaryInfo"":null,""allOrNone"":null,""houseAccountInfo"":""104""},""264"":{""firmMnemonic"":""FMST"",""houseAccountNum"":264,""houseSuffix"":null,""branchCode"":""A111"",""branchSeqno"":null,""floorBrokerNum"":""A111"",""secondaryFloorBrokerNum"":null,""billingIndicator"":null,""cust"":""\n"",""cmta"":null,""supplementaryInfo"":null,""allOrNone"":null,""houseAccountInfo"":""264""}}"
如何避免这种行为?
答案 0 :(得分:0)
private Serializer getSerializer() {
CsvConfiguration config = new CsvConfiguration();
config.setFieldDelimiter(';');
config.setDefaultQuoteMode(QuoteMode.NEVER); //!!!!
return CsvIOFactory.createFactory(config, MyCsvDto.class).createSerializer();
}