0
votes

I have json input as

{"subkeys":[{"1","2", "3"},{"4","5","6"},{"7","8","9"}]

I need to get this as List < List < String > > or List < String[] >.

@PUT
@Path("/{key}/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public MyResponse loadData( List<List<String>> subkeys) {

}

I got the error like

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions java.util.List is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at java.util.List at private java.util.List foobar.alkohol.register.webservice.jaxws.GetRelationsFromPersonResponse._return

1
Its not a valid JSON - Master Po
As the error says, java.util.List is an interface, and JAXB can't handle interfaces - OneCricketeer

1 Answers

-1
votes

The problem I can see here is due to the wrong format of the JSON input, the correct JSON in your case is:

{
  "data" :[
  {
  "keys": ["123","456","789"],

  "subkeys": [
      ["1", "2", "3"],
      ["1", "2", "3"],
      ["1", "2", "3"]
   ]
  }
  ]
}

try with this and let know.

my code is as follows

@PUT @Path("/{key}/") 
@Consumes(MediaType.APPLICATION_JSON) 
@Produces(MediaType.APPLICATION_JSON) 
public MyResponse loadData( MonitoringDataRequest monReq) {  
}

@XmlRootElement(name="data")
public class MonitoringDataRequest {
    private List<MonitoringData> data;

    @XmlElement
    public void setData(List<MonitoringData> data) {
        this.data = data;
    }


    public List<MonitoringData> getData() {
        return data;
    }




}

@XmlRootElement(name="monitoring_data")
public class MonitoringData {

    private List<String> keys;
    private List<SubkeyData> subKeys;

    @XmlElement
    public void setKeys(List<String> keys) {
        this.keys = keys;
    }


    public List<String> getKeys() {
        return keys;
    }


    @XmlElement(name="subkeys")
    public void setSubKeys(List<SubkeyData> subKeys) {
         this.subKeys = subKeys;
    }


    public List<SubkeyData> getSubKeys() {
         return subKeys;
    }

}

@XmlRootElement(name="subkeys")
//@XmlAccessorType(XmlAccessType.NONE)
public class SubkeyData 
{

    private List<String[]> subkeys;


    @XmlElement
    public void setSubkeys(List<String[]> subkeys)
    {
        this.subkeys = subkeys;
    }


    public List<String[]> getSubkeys()
    {
        return subkeys;
    }

}