My team are putting together a proof-of-concept Flex application sitting on top of a Spring-based server using BlazeDS.
We do quite a lot of date calculations, so we use Joda Time extensively throughout the code and in our domain model.
We're now trying to figure out how we can continue to use Joda Time in our DTOs that are sent back-and-forth with the Flex frontend via BlazeDS.
Our goal is to use the Actionscript 3 data type Date
on the Flex side and have that map to our use of Joda time's DateTime
, LocalDate
and LocalTime
types on the Java side.
We can solve the problem of converting Actionscript 3's Date
type when calling Java with a custom type marshaller plugged into BlazeDS, but this appears to only be invoked for the Flex->Java/BlazeDS direction and not for the Java/BlazeDS->Flex direction.
I'm now looking at custom PropertyProxy
implementations for BlazeDS, but this doesn't look like the right thing either.
The other idea was to implement Externalizable
on our Java DTOs, but this seems like too much work, especially when I look at the BlazeDS rival GraniteDS and that shows plugging in Joda Time support in their documentation with a simple type converter!
Any ideas appreciated.
For Java apps using the Spring-BlazeDS integration project from SpringSource, there is a much simpler way of handling this:
Write an implementation of GenericConverter that handles mapping ReadableDateTime to/from java.util.Date.
Create a subclass of AbstractAmfConversionServiceConfigProcessor and override configureConverters, adding your converter implementation to the registry.
Update your Spring configuration by creating an instance of your ConfigProcessor and wiring it up:
XML:
More info here:
http://static.springsource.org/spring-flex/docs/1.5.x/reference/html/index.html#amf-custom-converters
Have you tried the custom marshallers approach outlined on this blog:
http://flexblog.faratasystems.com/index.php/custom-type-masrhaller-in-blazeds
OK - I've found the answer on my own. This involved writing my own AMF endpoint class + related serializing classes. I've gotta say that the guys over at http://flexblog.faratasystems.com have been a great source of inspiration on hacking BlazeDS.
This code should really be incorporated into BlazeDS itself or some Open Source extension project - it's so basic.
Channel Definition
Custom AMF Endpoint
Custom Serializer
Custom AMF 0 Handling
Custom AMF 3 Handling
Custom Marshaller for Flex->Java Calling