简体   繁体   中英

Using ProperCase convention with Morphia and MongoDB

For legacy reasons (the database was created originally using .NET classes) my MongoDB documents all use ProperCase naming convention.

Is there a way to instruct Morphia to serialize/deserialize documents respecting this convention even if my properties on my POJOs are declared using camelCase, so I don't need to annotate all fields with @Property?

Right now, I am having to write this:

public class User {

  @Property("Name")
  public String name;

  @Property("Email")
  public String email;

  @Property("FacebookId")
  public String facebookId;

  ... 
}

There is no way currently to configure morphia like that. Morphia uses the field name by default so you could name your java fields that way and morphia would pick them up but then you'd be violating the standard Java conventions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM