I am trying to write a custom java.util.Date serializer for titan graph. Here is my titan configuration file:
attributes.allow-all = true
attributes.custom.attribute1.attribute-class = java.util.Date
attributes.custom.attribute1.serializer-class = com.serializer.MyDateSerializer
And My serializer looks like :
public class MyDateSerializer implements AttributeSerializer<Date> {
@Override
public void verifyAttribute(Date value) {
// TODO Auto-generated method stub
}
@Override
public Date convert(Object value) {
// TODO Auto-generated method stub
return null;
}
@Override
public Date read(ScanBuffer buffer) {
// TODO Auto-generated method stub
}
@Override
public void write(WriteBuffer buffer, Date date) {
// TODO Auto-generated method stub
}
}
But after opening the TitanGraph , I am getting the following exception:
java.lang.IllegalStateException: Need to set configuration value: root.attributes.custom.serializer-class
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at com.thinkaurelius.titan.diskstorage.configuration.ConfigOption.get(ConfigOption.java:158)
at com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration.get(BasicConfiguration.java:56)
at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.<init>(GraphDatabaseConfiguration.java:1334)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:91)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:71)
Here is how I am trying to read the configuration from the property file :
BaseConfiguration configuration = new BaseConfiguration();
Properties properties = new Properties();
properties.load(getClass().getResourceAsStream(
"/titanConfiguration.properties"));
Set<Entry<Object, Object>> entrySet = properties.entrySet();
for (Entry<Object, Object> entry : entrySet) {
configuration.setProperty(entry.getKey().toString(), entry
.getValue().toString());
}
I have gone through the titan graph documentation for the version 0.5.2, but Iam not able to figure out the problem. I have gone through similar posts also, but still I am not able to resolve this. Has anybody faced this problem before?
If I try to persist the java.util.Date inside titan vertex as follows :
vertex.setProperty("myDate",new Date());
And then when I try to retrieve the Date from vertex as :
((Date)vertex.getProperty("myDate"));
I get the following exception :
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
at org.rampal.Transaction.getUsers(Transaction.java:179)
at org.rampal.Controller.getUsers(Controller.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)