cancel
Showing results for 
Search instead for 
Did you mean: 

How to not trim strings in impex import?

Former Member
0 Kudos

Hi there

I was reading through other questions but did not find an answer.

I have a problem INSERT_UPDATE MyModel;uid[unique=true];name[lang=de];name[lang=en] ;test;Dear Mr. ;

Now Afterwards in the system the german name has no space at the end. Also with quotes it is not there but I need it.

What am I doing wrong?

Best regards Benjamin

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Unfortunately, I can't post a comment to Chris' one, so I'll put it as an answer

Here's the sample Decorator

 public class WhiteSpaceDecorator implements CSVCellDecorator
 {
 
     @Override
     public String decorate(final int position, final Map<Integer, String> srcLine)
     {
         final String parsedValue = srcLine.get(position);
         return parsedValue + " ";
     }
 
 }
 

When I run this script

 INSERT_UPDATE MyModel;code[unique=true];trimmedValue[cellDecorator=your.package.WhiteSpaceDecorator]
 ;1;value

Then I can see that the value of trimmedValue attribute is set to "value " instead of "value".

So decorator could help to add white space.

Former Member
0 Kudos

Hi Benjamin,

I think you have 2 options:

  1. Override CSVReader#readNextLine and skip the lines that trim inserted values or
  2. Create custom cell decorator which would add white space characters to cell values. Take a look at this article. The decorator is being called after the reader trimmed the value.

I would prefer the second approach.

Former Member
0 Kudos

Its a shame but neither the Translator or Decorator will help you, as both happen after the input is trimmed.

I can see no easy way to achieve this, as the entire thing is coded with the opposite assumption.

You could try overriding CSVReader, but this will not help you, as your override will never be used unless you also override large parts of hybris.