0

I am working on spring boot, and it is a rest application. Whenever I call "localhost:8080/projects", I get an json data in the given below form.

{
uid: "166"
    code: "99991"
        name: "iPOC AG Mednet - BIOC"
            protocol: "iPOC AG Mednet - BIOC"
                client: "BioClinica"
                    description: "AG Mednet - BIOC PoC "
                        platform: "BioPACS"
                            subjectConfiguration: {
    displayInitials: true
    displayDOB: true
    displayGender: true
}
uploadConfiguration: {
    hasAttachments: true
    hasNonDicom: false
    autoInserted: true
}}

But I need it in the below given format:

{
"_embedded" : {
"projects" : [ {
    "uid" : "1",
    "code" : "123",
    "name" : "Project 1",
    "protocol" : "Protocol 1",
    "client" : "Client",
    "description" : "",
    "platform": "BioPACS",
    "subjectConfiguration" : {
    "displayInitials" : true,
    "displayDOB" : true,
    "displayGender" : true
},
"uploadConfiguration" : {
    hasAttachments: true,
    hasNonDicom: true,
    isAutoInserted: false,
},
"_links" : {
    "self" : {
    "href" : "http://localhost:8080/projects/123"
}
}
}]}}

And my "project" Class is as given below.

public class Project {

private String uid;
private String code;
private String name;
private String protocol;
private String client;
private String description;
private String platform;
private SubjectConfiguration subjectConfiguration;
private UploadConfiguration uploadConfiguration;

public String getUid() {
    return uid;
}

public void setUid(String uid) {
    this.uid = uid;
}

public String getCode() {
    return code;
}

public void setCode(String code) {
    this.code = code;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getProtocol() {
    return protocol;
}

public void setProtocol(String protocol) {
    this.protocol = protocol;
}

public String getClient() {
    return client;
}

public void setClient(String client) {
    this.client = client;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String getPlatform() {
    return platform;
}

public void setPlatform(String platform) {
    this.platform = platform;
}

public SubjectConfiguration getSubjectConfiguration() {
    return subjectConfiguration;
}

public void setSubjectConfiguration(
        SubjectConfiguration subjectConfiguration) {
    this.subjectConfiguration = subjectConfiguration;
}

public UploadConfiguration getUploadConfiguration() {
    return uploadConfiguration;
}

public void setUploadConfiguration(UploadConfiguration uploadConfiguration) {
    this.uploadConfiguration = uploadConfiguration;
}

@Override
public String toString() {
    return "'uid':'" + uid + "', " + "'code':'" + code + "', "
            + "'name':'" + name + "', " + "'protocol':'" + protocol + "', "
            + "'client':'" + "', " + "'description':'" + description + "', "
            + "'platform':'" + platform + "', " + "'subjectConfiguration':'"
            + subjectConfiguration + "', " + "'uploadConfiguration':'"
            + uploadConfiguration + "'" ;
}}

And the method that returns the List is given below:

@RequestMapping(value = "/projects", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody List<Project> getProject() {
    GetAuthorizedWebSendTransferProjects request = new GetAuthorizedWebSendTransferProjects();
    GetAuthorizedWebSendTransferProjectsResponse response = gw.getResponse(request);
    JAXBElement<ArrayOfProjectContainer> arr = response.getGetAuthorizedWebSendTransferProjectsResult();
    ArrayOfProjectContainer arr1 = arr.getValue();
    List<ProjectContainer> arr2 = arr1.getProjectContainer();
    List<Project> projects = getPopulatedProjectList(arr2);
    return projects;
}

Do I need to add any library to achieve this or should I modify my toString() method of Project class. Now the response header has "Content-Type: application/json" but the headers that I require is "Content-Type: application/hal+json".Can anybody help me out to resolve this issue. Thank you in Advance.

1 Answer 1

3

I'd recommend using Jackson to convert the response you get from calling "localhost:8080/projects" to a JsonNode object. Then you can manipulate the JsonNode object however you want and populate your Project class with that data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.