[Logo] RSF Discussions Forum
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
EnJSONalizer  XML
Forum Index -> RSF Discussion
Author Message
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?
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
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.
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.
 
Forum Index -> RSF Discussion
Message Quick Reply
Go to:   
Powered by JForum 2.1.6 © JForum Team