4

I have this field in my domain object

@Field
@Enumerated(EnumType.STRING)
private SectionType sectionType;

but when I check the value stored in Solr it is something like:

com.x.y.objects.SectionType:H_HPI

What I want is just H_HPI or it is as if I'm calling specialty.name() method Also I want a serializer that does that for all the enum fields in my domain objects.

I know that for neo4j, for instance, has such a serializer and can be supplied to the field as an annotation. Also mongodb does the conversion automatically.

manish
  • 19,695
  • 5
  • 67
  • 91
biliboc
  • 737
  • 1
  • 10
  • 25
  • I faced the same problem and decided to dig into the code. SolrJ (the Apache Solr client) seems to convert the enum value to its fully qualified value. Since I could not figure out a simple solution with Spring Data Solr, I changed the stored field type to `String`, setting its value to `Enum.name()`. – manish Apr 12 '17 at 13:11
  • The Spring Data team has provided [a fix](https://github.com/spring-projects/spring-data-solr/commit/4bf0af3344ec9e92ac241eaa25883e73b08f3b0b) for this issue that should resolve the problem. – manish Apr 20 '17 at 05:48

1 Answers1

0

I had same problem and found this from Spring Data Solr codes

else if (fieldValue instanceof Enum) {
            field.setValue(this.getConversionService().convert(fieldValue, String.class), 1f);
        }

it sets the String value

https://github.com/spring-projects/spring-data-solr/commit/4bf0af3344ec9e92ac241eaa25883e73b08f3b0b

Vazgen Torosyan
  • 1,255
  • 1
  • 12
  • 26