How can I serialize and deserialize this object with gson to json:
public class test{
@Expose
public List< Pair<Double,Double> > list;
@Expose
public int alpha;
}
I've tried this:
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
String str = gson.toJson(testInstance,test.class);
where testInstance is an instance of class test, but it's not working because of Pair structure in List.
You have configured Gson object using excludeFieldsWithoutExposeAnnotation method.
From documentation:
Configures Gson to exclude all fields from consideration for serialization or deserialization that do not have the Expose annotation.
Could you change Pair class? If yes, you have to add @Expose annotation to each property which you want serialize to JSON. If no, you can create similar class in your program and add annotations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With