0

Let's assume a simple User class (with a public field just for the sample) like this:

public class User {
   public UserId userId; 
}

public class UserId {
   public String value = "1"; //hardcoded for the example
}

When Spring has to demand a serialization in order to make a remote call involving a User object, the UserId field is well serialized to "1".

However, when I annotate the UserId field with some Spring annotation, in my case @Indexed from Spring-Data-Neo4j, I get this stack:`

RuntimeException: : org.codehaus.jackson.map.JsonMappingException: No serializer found for class com.model.user.UserId and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.HashMap["value"])  (JsonHelper.java:77)
[error] org.neo4j.rest.graphdb.util.JsonHelper.createJsonFrom(JsonHelper.java:77)
[error] org.neo4j.rest.graphdb.ExecutingRestRequest.post(ExecutingRestRequest.java:140)
[error] org.neo4j.rest.graphdb.ExecutingRestAPI.addToIndex(ExecutingRestAPI.java:410)
[error] org.neo4j.rest.graphdb.RestAPIFacade.addToIndex(RestAPIFacade.java:166)
[error] org.neo4j.rest.graphdb.index.RestIndex.add(RestIndex.java:60)

Annotation seems to cause this to break. Is there a good reason to this? Is there a way to serialize it although an annotation is present?

Mik378
  • 21,881
  • 15
  • 82
  • 180
  • It may not be exactly the same problem, but take a look at [this question](http://stackoverflow.com/questions/4362104/strange-jackson-exception-being-thrown-when-serializing-hibernate-object) – a better oliver Dec 23 '13 at 21:12
  • Similar to: http://forum.spring.io/forum/spring-projects/data/nosql/110063-unable-to-convert-nodeentity-object-to-json-with-jackson – Mik378 Dec 24 '13 at 01:32
  • You should post some real code and explain your real use case (Spring Data Neo4j) as the problem simply does not exist in your example. Both your link and mine explain that the problem can be caused by proxies or load-time-weaving. – a better oliver Dec 24 '13 at 10:21

1 Answers1

1

Add a serializer/converter for your custom class andr register it in context.

Jackson doesn't,t know how to convert your class to Json unless you tell it how.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • So why does it well work without the annotation ? I've already tried with a custom converter but it still does not work – Mik378 Dec 23 '13 at 20:42