I have a class that implements Iterable. When using FlexJSON, the iterator gets used serialize the class by default. For this specific class, I need it to be serialized like a normal class; specifically, there's a float[] of x,y coordinates that need to be saved. The iterator loops through this float array, but outputs them as a convenience class XPoint. This results in FlexJSON saving serializing the class as an array of XPoints rather than a float[].
I've tried using all the ways of setting the transformer to a ClassTransformer, but this ends up causing ObjectTransformer to throw an exception. I also tried extending ArrayTransformer so that it will deliberately pass the desired array from the object, to no avail:
Same error, don't really know if it made sense to begin with anyways.
I'll include the code for the class below, but I'm assuming there's something obvious I'm missing to do this. I know I could just not implement Iterable, but that seems like a pretty bad solution.
I have a class that implements Iterable. When using FlexJSON, the iterator gets used serialize the class by default. For this specific class, I need it to be serialized like a normal class; specifically, there's a float[] of x,y coordinates that need to be saved. The iterator loops through this float array, but outputs them as a convenience class XPoint. This results in FlexJSON saving serializing the class as an array of XPoints rather than a float[].
I've tried using all the ways of setting the transformer to a ClassTransformer, but this ends up causing ObjectTransformer to throw an exception. I also tried extending ArrayTransformer so that it will deliberately pass the desired array from the object, to no avail:
Same error, don't really know if it made sense to begin with anyways.
I'll include the code for the class below, but I'm assuming there's something obvious I'm missing to do this. I know I could just not implement Iterable, but that seems like a pretty bad solution.
Example JSON from FlexJSON:
Last edit: Robert Liberatore 2015-05-14
Well, guess I should have waited five more minutes before posting. Solved the issue with a better understanding of custom transformers:
~~~~~~
public class PointListTransformer extends AbstractTransformer {
@Override
public void transform(Object object) {
final float[] array = ((PointList) object).getArray();
getContext().transform(array);
}
}
~~~~~~~
with .transform(new PointListTransformer(), PointList.class) in the serializer. Here's hoping it works with the deserializer as well....