title: Spring Data Mongo cannot find PersistentEntity for Enum
body: <p>Edit: I found a related question <a href="https://stackoverflow.com/questions/28972455/does-spring-data-mongodb-support-enums">here</a>, but the only 2 answers contradict each other, and there was not enough information to address my use case.</p>
  
  <p>I am trying to use Spring Data Mongo to load records from a collection. One of the fields within those records is an Enum, defined as such:</p>
  
  <pre class="lang-java prettyprint-override"><code>@AllArgsConstructor
  @Getter
  @JsonFormat(shape = JsonFormat.Shape.OBJECT)
  public enum Action {
      APPROVED("Approved"),
      SAVED("Saved"),
      CORRECTED("Corrected");
  
      private String name;
  
      @JsonCreator
      static Action findValue(@JsonProperty("name") String name) {
          return Arrays.stream(Action.values()).filter(v -&gt; v.name.equals(name)).findFirst().get();
      }
  }
  </code></pre>
  
  <p>This should define enums to be serialized and deserialized according to a JSON representation: <code>{"name": "Saved"}</code> for example.</p>
  
  <p>Jackson seems to be working fine, since I threw an API call at it and told it to expect an <code>Action</code> type, and it read the enum without any issues.</p>
  
  <pre class="lang-java prettyprint-override"><code>public void save(@RequestBody @Valid Action action) {
      System.out.println(action.getName());
  } // successfully prints the name of whatever Action I give
  </code></pre>
  
  <p>However, when I try to read an object with an Action field using Spring Data Mongo, I get the following:</p>
  
  <pre><code>Expected to read Document Document{{name=Corrected}} into type class package.structure.for.some.proprietary.stuff.constants.Action but didn't find a PersistentEntity for the latter!
  </code></pre>
  
  <p>So I'm thinking Spring Data Mongo just can't make heads or tails of these enums for whatever reason. But I'm not sure how to help it register that as a PersistentEntity. The main class of my Spring Boot app is in package <code>package.structure.for.some.proprietary.stuff</code> and is annotated as such:</p>
  
  <pre class="lang-java prettyprint-override"><code>@ComponentScan("package.structure")
  @EnableTransactionManagement
  @EnableAutoConfiguration
  @SpringBootApplication
  </code></pre>
  
  <p>The object in particular I'm trying to read is defined by this POJO:</p>
  
  <pre class="lang-java prettyprint-override"><code>import java.util.Date;
  
  import org.springframework.data.annotation.Id;
  import org.springframework.data.mongodb.core.mapping.Document;
  
  import lombok.Data;
  import lombok.NonNull;
  
  import package.structure.for.some.proprietary.stuff.constants.Action;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @JsonPropertyOrder({
      "timeStamp",
      "action",
  })
  @Data
  @Document(collection = "sample_coll")
  public class Sample {
      @Id
      @JsonIgnore
      private String id = null;
  
      @JsonProperty("timeStamp")
      @NonNull
      private Date timeStamp;
      @JsonProperty("action")
      @NonNull
      private Action action;
  }
  </code></pre>
  
  <p>and is queried from the collection with a MongoRepository:</p>
  
  <pre class="lang-java prettyprint-override"><code>public interface SampleRepository extends MongoRepository&lt;Sample, String&gt; {
  
  }
  </code></pre>
  
  <p>using <code>SampleRepository.findAll();</code></p>
  
  <p>So my big question is, how do I get Spring Data Mongo to recognize this enum Action as a PersistentEntity?</p>