bulbs icon indicating copy to clipboard operation
bulbs copied to clipboard

Dictionary() property doesn't work due to invalid hashmap conversion

Open chiffa opened this issue 11 years ago • 4 comments

When the Dictionary property is attached and used the following error arises:

SystemError: ({'status': '200', 'content-length': '110', 'content-type': 'application/json; charset=UTF-8', 'access-control-allow-origin': '*', 'server': 'Jetty(6.1.25)'}, '"java.lang.IllegalArgumentException: Unknown property type on: {nom=1, mnom=1}, class java.util.LinkedHashMap"')

chiffa avatar Aug 03 '14 18:08 chiffa

Some DBs such as Neo4j don't allow properties to be dictionaries (only primitive arrays). In this case you can use the Bulbs Document type instead of Dictionary -- the Document type converts Python dicts to JSON string before writing to the DB, and it converts JSON strings back to Python dicts when read from the DB.

espeed avatar Aug 04 '14 05:08 espeed

Great, would you mind providing more info about the Document type? I couldn't find it in the usual property documentation location: http://bulbflow.com/docs/api/bulbs/property/#property

chiffa avatar Aug 04 '14 15:08 chiffa

The online docs need to be updated. The Document Property is defined here:

  • https://github.com/espeed/bulbs/blob/master/bulbs/property.py#L456

And here's how it gets called when using the default JSON type system:

  • https://github.com/espeed/bulbs/blob/master/bulbs/json.py#L154

NOTE: The Document Property definition uses the JSON type system's to_document() method to convert a Python dict to a JSON string when saving to the database, but it uses the to_dictionary() method to convert the JSON string to a Python dict when reading from the database.

espeed avatar Aug 04 '14 16:08 espeed

Great, thanks. Would you mind adding it to doc in a future release?

chiffa avatar Aug 04 '14 18:08 chiffa