0

I have a JSON file like this :

{
    "rewrite_url_captures": [
        {
            "description": [
                "Captures arguments in a URL and rewrites the URL using these arguments. "
            ],
            "configuration": {},
            "name": "URL Rewriting with Captures"
        }
    ],
    "routing": [
        {
            "description": [],
            "configuration": {},
            "name": "Routing"
        }
    ],
    "soap": [
        {
            "description": [
                "This policy adds support for a very small subset of SOAP."
            ],
            "configuration": {},
            "name": "SOAP"
        }
    ]
}

I would like to get the names of these 3 objects: rewrite_url_captures, routing, soap.

I already did this :

import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
    "rewrite_url_captures"
})
public class PoliciesTest {

    protected ArrayList<PolicyTest> policy;

    @JsonProperty("rewrite_url_captures")
    public ArrayList<PolicyTest> getPolicy() {
        if (policy == null) {
            policy = new ArrayList<PolicyTest>();
        }
        return this.policy;
    }
}

That calls this class :

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
        "name"
})
public class PolicyTest {

    @JsonProperty("name")
    private String name;

    public Object getName() {
        return name;
    }
}

I get this as output so it works :

Output

My problem is that I can only access the 3 objects one by one by modifying the JSON property with the corresponding name in the PoliciesTest class, except I would like to have the 3 at once as an output and I can't overload the @JSONProperty.

Has anyone faced this problem before?

HariHaravelan
  • 840
  • 8
  • 17
  • Does this answer your question? [DE serialize .json file into java object](https://stackoverflow.com/questions/72024604/de-serialize-json-file-into-java-object) – Michael Gantman Apr 27 '22 at 08:12
  • Using the org.json library might solve your problem. But you have to manually get the object from the json. – DILIP KUMAR Apr 26 '22 at 16:24

0 Answers0