How do i map this json response correclty?

Viewed 94

Im having trouble mapping this wikipedia opensearch json response to my model. Im using gson to map the response

[
    "Computer",
    [
        "Computer",
        "Computer program",
        "Computer science",
        "Computer network",
        "Computer keyboard",
        "Computer mouse",
        "Computer security",
        "Computer virus",
        "Computer data storage",
        "Computer hardware"
    ],
    [
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        ""
    ],
    [
        "https://en.wikipedia.org/wiki/Computer",
        "https://en.wikipedia.org/wiki/Computer_program",
        "https://en.wikipedia.org/wiki/Computer_science",
        "https://en.wikipedia.org/wiki/Computer_network",
        "https://en.wikipedia.org/wiki/Computer_keyboard",
        "https://en.wikipedia.org/wiki/Computer_mouse",
        "https://en.wikipedia.org/wiki/Computer_security",
        "https://en.wikipedia.org/wiki/Computer_virus",
        "https://en.wikipedia.org/wiki/Computer_data_storage",
        "https://en.wikipedia.org/wiki/Computer_hardware"
    ]
]

The URL: https://en.wikipedia.org/w/api.php?action=opensearch&search=Computer&format=json

My model:

import lombok.Data;

@Data
public class OpensearchResponse {

    String searchTerm;

    String[] possibilities;

    String[] empty;

    String[] references;
    
}

When i try to map the json respone like so:

var opensearchResponse = gson.fromJson(jsonResponse, OpensearchResponse.class);

I get this error

Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

I suspect my data structure is very wrong. But what exactly?

0 Answers
Related