Cannot convert Enum to int using Spring Converter

311 Views Asked by At

My application uses BlazeDS for communication between Flex and Java. I'm using Spring for BlazeDS integration in Java.

I have an enum called TransactionStatus. On the flex side, the corresponding properties are set as integers. I'm trying to use custom converters to handle this conversion. Here are my converters:

public class TransactionStatusIntConverter implements Converter<TransactionStatus, Integer> {

    @Override
    public Integer convert(TransactionStatus src) {
        if(src == null){
            return 0;
        } else {
            return src.getValue();
        }
    }

}

And

public class IntTransactionStatusConverter implements Converter<Integer, TransactionStatus> {

    @Override
    public TransactionStatus convert(Integer src) {
        return TransactionStatus.fromInt(src);
    }

}

When sending data from the Flex client to Java, the conversion succeeds and I get a TransactionStatus instance as expected. But when sending data from Java to Flex, the conversion function is never executed. Both the converters are definitely registered in my ConfigProcessor class

@Override
protected void configureConverters(ConverterRegistry registry) {
    registry.addConverter(new IntTransactionStatusConverter());
    registry.addConverter(new TransactionStatusIntConverter());
}

What's going on here?

0

There are 0 best solutions below