Problem when inserting object with hashmap which keys contain a dot
See original GitHub issueRe-opens #268
I encountered this issue as well and reproduced it :
static class MyObjectWithMap {
Map<String, String> map = Maps.newHashMap();
}
MyObjectWithMap obj = new MyObjectWithMap();
obj.map.put("keyOk", "OK");
getDs().save(obj); // No problem
obj.map.put("key.notOK", "notOK");
getDs().save(obj); // Problem
Generates this :
java.lang.IllegalArgumentException: Invalid BSON field name key.notOK
at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:494)
at com.mongodb.DBObjectCodec.encodeMap(DBObjectCodec.java:219)
at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:198)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:128)
at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:61)
at com.mongodb.CompoundDBObjectCodec.encode(CompoundDBObjectCodec.java:48)
at com.mongodb.CompoundDBObjectCodec.encode(CompoundDBObjectCodec.java:27)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How does a Java HashMap handle different objects with the ...
get(key): HashMap uses Key Object's hashcode to find out bucket location and then call keys.equals() method to identify correct node in LinkedList and...
Read more >HashMap containsKey() Method in Java - GeeksforGeeks
The java.util.HashMap.containsKey() method is used to check whether a particular key is being mapped into the HashMap or not.
Read more >How HashMap works in Java - Javarevisited
In hashing, hash functions are used to link keys and values in HashMap. Objects are stored by the calling put(key, value) method of...
Read more >Using a Custom Class as a Key in a Java HashMap | Baeldung
A Map doesn't allow duplicate keys, so the keys are compared to each other using the Object#equals(Object) method. Because this method has ......
Read more >How to use User defined Object as key in HashMap with an ...
Please check out my blog(http://learnsimple.in) for more technical videos.For any java/full stack/DevOps/developer/lead positions related ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there any generic workaround? We’re storing a document with generic JSON content (i.e. we do not control the key names). I’m thinking of having some pre/postprocessor that replaces invalid keys with an encoded version and replaces them upon reading. Maybe defining a special JsonMap class which would know to do the proper processing.
Not directly because embedded objects don’t have a lifecycle separate from the enclosing type. If you’d like help with the listeners, please post your questions to the mailing list https://groups.google.com/forum/#!forum/morphia.
--------------------------------
{ *name : *“Justin Lee”, * title : *“Software Engineer”, twitter : "@evanchooly http://twitter.com/evanchooly_"_, web : [ “mongodb.com http://www.mongodb.com”, “antwerkz.com” ], location : “New York, NY” }
On Wed, Jan 20, 2016 at 2:25 PM, plaa notifications@github.com wrote: