Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

parsing a json to a List<List<String>

1102964Jun 13 2017 — edited Jun 13 2017

I have json input as

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

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

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( 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;

    }

}


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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2017
Added on Jun 13 2017
0 comments
563 views