Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for non-String keys in a Map #181

Open
davidjoh0 opened this issue Oct 3, 2017 · 3 comments
Open

Support for non-String keys in a Map #181

davidjoh0 opened this issue Oct 3, 2017 · 3 comments

Comments

@davidjoh0
Copy link

Hello,

We get an error when we try to save an entity which contains a Map with an enum as the key. Is there a workaround for this, e.g. a PropertyMapper?

Catatumbo provides an enum mapper, could this be applied to an enum as a Map key?

Thanks,

David

@sai-pullabhotla
Copy link
Owner

@davidjoh0 - The current implementation expects/requires that the keys of a Map are Strings. The purpose of EnumMapper is different than what you need. In essence, the developers (through an annotation) provide a way to convert a Map's key into String (while writing to the Datastore) and String to Map's key (while reading from the Datastore). I've marked this as an enhancement request. If you are willing to contribute, let me know.

@sai-pullabhotla
Copy link
Owner

A temporary solution could be to attach a custom mapper for your map field and let the mapper handle the data mapping to/from Datastore. If you plan to have many maps with all types of keys, this may not be the best solution. A customer mapper can be attached as shown below:

@Entity
public class MyEntity {
  @Identifier
  private long id;

  //Attach a custom mapper 
  @PropertyMapper(MyMapMapper.class)
  private Map<MyEnum, String> myMap;
}

Provide the implementation in MyMapMapper.

@davidjoh0
Copy link
Author

@sai-pullabhotla many thanks for the responses and advice.

Just to clarify; in the current implementation it is not possible to add a Enum<>String mapper to a Map key (this would require changes in the framework), but I could build a custom property mapper which could fix our specific issue.

I will proceed with the custom mapper solution.

btw, the catatumbo framework is very useful and has been easy to use!

Many thanks,

Dave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants