Yan.F
Yan.F

Reputation: 640

How to Ignore fields when using JSONArray in Java

I want to ignore some fields when using JSONArray:

public class Person {
private Integer id;
private String name;
//field to ignore in json
private Account account;
...

Here I use JSONArray:

public static JSONArray listToJson(List objects) throws JSONException {
    return new JSONArray(objects);

}

Upvotes: 1

Views: 291

Answers (1)

Antony Dao
Antony Dao

Reputation: 425

You can use transient key word for it.

private transient Account account;

Variables may be marked transient to indicate that they are not part of the persistent state of an object.

Upvotes: 2

Related Questions