| Author |
Message |
![[Post New]](/rsf/templates/default/images/icon_minipost_new.gif) 15/02/2009 16:22:13
|
krishnas
Request-scope Wrangler
Joined: 22/01/2008 05:22:29
Messages: 10
Offline
|
The EnJSONalizer class gives a StackOverFlow error especially if there are circular references ( due to bidirectional association) in the domain model. Especially this breaks down from custom written enums where the enums have methods like getAllPossibleValues which in turn refers to the Enum.
Should I try to fix my design or is there a override to make stop to the parsing descension by using a custom toJson() method or custom parser registrations?
|
|
|
 |
![[Post New]](/rsf/templates/default/images/icon_minipost_new.gif) 16/02/2009 13:35:41
|
antranig
Request-scope Wrangler
Joined: 03/04/2006 13:29:55
Messages: 643
Offline
|
Yes, there are a few ways round this - certainly "raw" encoding of some Java constructs (enums and other kinds of non-Pojos) will probably have unhelpful results with respect to a client-side as well as the implementation unhappiness that you mention. You could try adjusting your design, or else, forming a kind of sanitized "DTO" representation for serializing, perhaps simply using Maps or just reduced POJOs. And yes, you could also try a serialization library of your choice, such as JSONLib, and simply produce a ready-serialized String for the client-side, if your desired data needs too much conformance.
I will add the circular overflow bug for the upcoming release, thanks -
https://bugs.caret.cam.ac.uk/browse/RSF-137
|
|
|
 |
![[Post New]](/rsf/templates/default/images/icon_minipost_new.gif) 16/02/2009 20:37:40
|
krishnas
Request-scope Wrangler
Joined: 22/01/2008 05:22:29
Messages: 10
Offline
|
Thanks Antranig for your reply. For the Enum case - all the enums extended a base AbstractEnum - so I injected the ELContextMapping into my producer and registered a generic custom leaf parser for the AbstractEnum class into the ELContextMapping.generalLeafParser. I then was able to render the Multiple Enum types - their instance values to be exact using duck typing - where "type" full class name of the Enum and value is the String representation of the value as JSON object. On the way in I parsed this using the JSONObject ( from JSON lib) - the type and value as key value pairs and was able to convert into the Java Enum representation.
So one parser took care of all Enums in my system.
What I would like is to some way of adding specific class parsers directly into the ELMappingContext in the Application Context itself - without having to inject that into my producer. Currently the registerParser in generalLeafParser - is there a way to make a call to arbitrary methods in Spring contexts. This is more a Spring question than a RSF question.
|
|
|
 |
![[Post New]](/rsf/templates/default/images/icon_minipost_new.gif) 17/02/2009 02:59:42
|
antranig
Request-scope Wrangler
Joined: 03/04/2006 13:29:55
Messages: 643
Offline
|
Well, here you probably just want to write a bean which has the relevant mapping context injected into it, which it invokes methods on - that is, in this case, to "go against the flow" of IoC - there are examples in the central RSF mapping loader of how to do this for the various kinds of mappings -
https://source.caret.cam.ac.uk/rsf/projects/RSFUtil/trunk/src/uk/org/ponder/rsf/mappings/RSFMappingLoader.java
The answer to your general question (which is probably not quite what you wanted) is Spring's "MethodInvokingFactoryBean" -
http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/beans/factory/config/MethodInvokingFactoryBean.html
Cheers,
Boz.
|
|
|
 |
|
|