I have one main document:
@Document
public class MainDocument {
private String name;
private String desc;
private List<Nested> nestedList;
-- More fields/methods --
}
and a document getting embedded:
@Document
public class Nested {
private String nestedUser;
private String nestedTitle;
-- More fields/methods --
}
When attempting to store a new instance of the Nested class in List<Nested>
, the fields of the Nested class are getting renamed. For example, nestedTitle
becomes title
. This wouldn't be a huge deal except for the fact that it is not allowing me to set the value of some of the renamed fields.
I have tried using the @Field("field_name")
annotation but the fields will still get renamed and ignore attempts to set their value.
What would be causing some of the fields to get renamed? Am I missing something? About half of the fields get renamed and the rest stay the correct name...
I am testing by using POSTMAN to send JSON requests to the controller for the main document. Even if I use the new field name in the JSON request the value will still not be set.
Figured it out...
Getter method for nestedTitle
was named getTitle()
so it was renaming it based on the getter methods name. Changed to getNestedTitle()
and it stopped getting renamed. Changed the other getter methods for the fields in question and now everything works as expected.
Not sure why it would rename the field's based on the method name but who am I to judge Spring... Posting this answer to save someone else a couple hours of their time.