Reputation: 1847
Just migrated orientdb from v2.1.19 to v3.0.2 and there is an issue with the code I was using.
Basically doing this now throws a cast exception :
Map<String, String> myMap = vertex.getProperty("myMap");
String test = new ObjectMapper().writeValueAsString(myMap);
Where
myMap
: Embedded map property of the vertex
vertex in the orientdb database.ObjectMapper
: com.fasterxml.jackson.databind.ObjectMapper
the serializer provided by Jackson.Full error label : com.fasterxml.jackson.databind.JsonMappingException: com.orientechnologies.orient.core.id.ORecordId cannot be cast to java.lang.String
Why is it that ORecordId
can not be cast to String
anymore ?
Only solution I see : detect that there is a ORecordId
in the map and transform it manually into a String
. This doesn't seem like a fit to me.
Upvotes: 1
Views: 170
Reputation: 1847
The solution I used (I'm not really fond of it)
I created a method that handle the retrieved property as Map<String, Object>
public static Map<String, String> convertToStringMap(Map<String, Object> map) {
if (map == null)
return null;
return map.entrySet().stream().collect(Collectors.toMap(
entry -> entry.getKey(),
entry -> entry.getValue().toString()));
}
Then I can retrieve my embedded map as a Map<String, String>
this way
Map<String, String> myMap = convertToStringMap(vertex.getProperty("myMap"))
// Do something with
// (both throw an exception if no passed through convertToStringMap)
String test = new ObjectMapper().writeValueAsString(myMap); // serialize
System.out.println(my.get("anEntryKey")); // print
Upvotes: 1