@Convert into multiple attributes

Consider the following classes:

@NodeEntity
class MyClass {
	@Id @GeneratedValue
	Long iid;
	List<Attribute> attributes;
}

class Attribute {
	String name;
	String value;
}

In order to be able to store "attributes" in the node corresponding to the MyClass object without a need to store each attribute as a distinct node, I want to convert them to multiple attributes when saving to neo4j, something like this:

@NodeEntity
class MyClass {
	@Id @GeneratedValue
	Long iid;
	String attribute_name1; // (which stores value1)
	String attribute_name2; // (which stores value2)
	String attribute_name3; // (which stores value3)
}

However, it seems that @Convert is only able to convert an attribute to a single attribute with the same name not several attributes with different names. I would be happy to be able to do something like this:

@NodeEntity
class MyClass {
	@Id @GeneratedValue
	Long iid;
	@MultipleConvert(MyConverter.class)
	List<Attribute> attributes;
}

class MyConverter<T> implements IMultipleConvert<T>{
	@Override
	public List<Pair<String, String>> toGraphProperty(List<T> list) {
		...
		return convertedList;	// This returns, e.g., [{name1, value1}, {name2, value2}] which will be stored as attributes "attribute_name1", ... in the graph node.
	}
	@Override
	public List<T> toGraphProperty(List<Pair<String, String>> list) {
		...
		return convertedList;
	}
}

Is it possible in Neo4j OGM? If not, is there any plan to add it?
Is it possible that the graph properties have different types (e.g., one is a number, another is a string)?

Seems like a good case for using lists, which are supported in OGM and Neo4j.

Also note that graph properties do have different types (the current documentation can be misleading).

CompositeAttributeConverter seems to be the solution to my problem. It supports properties having different types.

1 Like