FlexJson - Unable to serialize Double []

I have a simple custom class with the Double [] variable to indicate the location of the user.

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

This is the code I tried with serializing a User object

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

But the location field will not be serialized, other fields will be serialized, though .. Can someone help?

Thanks!

+4
source share
2 answers

Just declaring a variable is not enough, because by default it was initialized to null.

Either set the value using the setter method, or initialize it using an empty array, for example:

private Double[] location = new Double[10];
0
source

, :

final String[] includedFields = {"location"}; 

new JSONSerializer()
                    .include(includedFields)
                    .serialize(object));
0

Source: https://habr.com/ru/post/1609096/


All Articles