FaKod/neo4j-scala — Issue #4: Handling of null values
Author: dozed
Created: 2011-10-26 21:13:11+00:00
State: open

Serializing case classes with parameters whose value are null is currently not possible.
The following version works for me. Could you check if this is a reasonable patch?

https://github.com/FaKod/neo4j-scala/blob/master/src/main/scala/org/neo4j/scala/util/Poso.scala#L47

```scala
def deserialize(m: Map[String, AnyRef], javaTypeTarget: JavaType) = {
require(javaTypeTarget.c.getConstructors.length == 1, "Case classes must only have one constructor.")
val constructor = javaTypeTarget.c.getConstructors.head
val params = sigParserCache.getOrElseUpdate(javaTypeTarget.c, CaseClassSigParser.parse(javaTypeTarget.c))

val values = new ArrayBuffer[AnyRef]
for ((paramName, paramType) <- params) {
val field = m.getOrElse(paramName, throw new RuntimeException("Field: " + paramName + " of type: " + paramType.c + " not found"))

field match {
case Some(_) => values += field.get
case None => values += null
}
}
constructor.newInstance(values.toArray: _*).asInstanceOf[AnyRef]
}
```

https://github.com/FaKod/neo4j-scala/blob/master/src/main/scala/org/neo4j/scala/Neo4jWrapper.scala#L131

```java
def serialize[T <: PropertyContainer](cc: AnyRef, pc: PropertyContainer): T = {
CaseClassDeserializer.serialize(cc).foreach {
case (name, null) =>
case (name, value) => pc.setProperty(name, value)
}
pc(ClassPropertyName) = cc.getClass.getName
pc.asInstanceOf[T]
}
```