Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlexJson - Unable to Serialize Double[] array

I have a simple user class with a Double[] variable for specifying a user's location.

@Document
public class User {
    private long id;
    private Double[] location;
}

This is the code that i have tried with to serialize my User object

new JSONSerializer()
           .transform(new ArrayTransformer(), Double[].class)
           .serialize(object));

But the location field won't get serialized, other fields are serialized though.. Could someone please help?

Thanks!

like image 888
user1955934 Avatar asked Oct 30 '22 18:10

user1955934


1 Answers

Just declaring the variable isn't enough since it's initialized to null by default.

Either set a value using setter method or initialize it with and empty array, for example:

private Double[] location = new Double[10];
like image 142
Amila Avatar answered Nov 02 '22 11:11

Amila