Skip to content
Snippets Groups Projects

Cherry-pick 'Fix parsing string arrays' into release/0.25

Merged Chad Leong requested to merge cherry-pick-for-693 into release/0.25
14 files
+ 285
21
Compare changes
  • Side-by-side
  • Inline
Files
14
@@ -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;
@@ -91,7 +95,7 @@ public class AttributeParsingServiceImpl implements IAttributeParsingService {
}
try {
List<String> parsedStringList = isArrayType(attributeVal);
List<String> parsedStringList = isArrayType(attributeVal, attributeClass);
List out = new ArrayList<>();
for (Object o : parsedStringList) {
out.add(parser.apply(attributeName, o));
@@ -232,8 +236,17 @@ public class AttributeParsingServiceImpl implements IAttributeParsingService {
}
private List<String> isArrayType(Object attributeVal) {
try {
private List<String> isArrayType(Object attributeVal, Class<?> attributeClass) {
// Handling string arrays as they're not valid JSON for code below
if (attributeVal != null && attributeClass == String.class && attributeVal instanceof List<?>) {
List<String> result = new ArrayList<>();
for (Object item: (List<Object>)(List<?>) attributeVal) {
result.add(item == null ? null : String.valueOf(item));
}
return result;
}
try {
String value = attributeVal == null ? null : String.valueOf(attributeVal);
if (attributeVal == null || Strings.isNullOrEmpty(value)) {
return Collections.EMPTY_LIST;
Loading