Skip to content
Snippets Groups Projects
Commit 6198cc35 authored by Stanisław Bieniecki's avatar Stanisław Bieniecki Committed by Chad Leong
Browse files

Fix parsing string arrays

(cherry picked from commit b11b2705)
parent ee156ee4
No related branches found
No related tags found
1 merge request!703Cherry-pick 'Fix parsing string arrays' into release/0.25
......@@ -64,8 +64,12 @@ public class AttributeParsingServiceImpl implements IAttributeParsingService {
@Override
public void tryParseValueArray(Class<?> attributeClass, String recordId, String attributeName, Object attributeVal, Map<String, Object> dataMap) {
BiFunction<String, Object, ?> parser;
ElasticType elasticType = ElasticType.forValue(attributeClass.getSimpleName());
ElasticType elasticType = attributeClass != String.class ? ElasticType.forValue(attributeClass.getSimpleName()) : ElasticType.TEXT;
switch (elasticType) {
case TEXT:
case KEYWORD:
parser = this.stringParser::parseString;
break;
case DOUBLE:
parser = this.numberParser::parseDouble;
break;
......
......@@ -114,11 +114,13 @@ public class StorageIndexerPayloadMapper {
switch (elasticType) {
case KEYWORD:
case KEYWORD_ARRAY:
case TEXT:
case TEXT_ARRAY:
this.attributeParsingService.tryParseString(recordId, schemaPropertyName, storageRecordValue, dataCollectorMap);
break;
case KEYWORD_ARRAY:
case TEXT_ARRAY:
this.attributeParsingService.tryParseValueArray(String.class, recordId, schemaPropertyName, storageRecordValue, dataCollectorMap);
break;
case INTEGER_ARRAY:
this.attributeParsingService.tryParseValueArray(Integer.class, recordId, schemaPropertyName, storageRecordValue, dataCollectorMap);
break;
......
......@@ -227,6 +227,21 @@ public class AttributeParsingServiceImplTest {
assertEquals(dataMap.get("side"), "true");
}
@Test
public void should_parseValidStringArray() {
Map<String, Object> dataMap = new HashMap<>();
final Map<Object, Object> inputs = new HashMap<Object, Object>() {
{
put("[]", new String[]{});
put("[test]", new String[]{"test"});
put("[aaa, bbb]", new String[]{"aaa", "bbb"});
put("[\"139.987\", \"20\"]", new String[]{"139.987", "20"});
}
};
this.validateInput(this.sut::tryParseValueArray, String.class, String.class, inputs, dataMap);
}
@Test
public void should_parseDate_tryParseDate() {
Map<String, Object> dataMap = new HashMap<>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment