1

I have the following request

{
  "name":"Ajeesh",
  "description":"hello",
  "platform_settings":[
      {"key":"value"},
      {"key1":"key2"}..  // This key value can be anything upto n times
  ]
}

I have created a POJO for the above as follows

package com.payunow.socialsharemodule.models;

import com.fasterxml.jackson.databind.ObjectMapper;// in play 2.3
import java.util.List;
import java.util.Map;

public class Share {
    private String name;
    private String description;


    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

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

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


    @Override
    public String toString(){
        return getName() + ", "+getDescription();
    }
}

How will I define platform_settings array of objects when converting the JSON to Java objects?

1 Answer 1

5

You could declare platform_settings as a list of maps:

 public class Share {
    private String name;
    private String description;
    private List<Map<String, String>> platform_settings;

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

2 Comments

Probably should do Map, not HashMap. Let Jackson decide both List and Map implementation.
@Ajeesh Good. If it helped you, pls accept my answer.

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.