So you want the List to have a different name and remain 'wrapped' but have the elements unwrapped? I would take a look at JSONConfiguration and the user's guide section [1] to see if what you are looking for is discussed. Not sure if using natural notation with root unwrapping set to false will do exactly what you want.
-Noah
[1] -
http://jersey.java.net/nonav/documentation/latest/user-guide.html#json
On May 26, 2011, at 9:03 PM, Maxrunner wrote:
> So the class organicas is a different class from where the method :
>
> public Organicas getOrganicas() {
> ...
> return new Organicas(organicas);
> }
>
>
> is from?
>
> regards,
> On Thu, May 26, 2011 at 10:49 PM, Daniel Larsson [via Jersey] <[hidden email]> wrote:
> This should change "List" to "organicas", I believe:
>
> public class Organicas {
> private List<OrganicaMobileEntity> organicas;
>
> public Organicas(List<OrganicaMobileEntity> organicas) {
> this.organicas = organicas;
> }
>
> List<OrganicaMobileEntity> getOrganicas() { return organicas; }
> }
>
> @GET
> @Produces(MediaType.APPLICATION_JSON)
> @Path("/getAllOrganicas")
> public Organicas getOrganicas() {
> ...
> return new Organicas(organicas);
> }
>
>
> 2011/5/25 Maxrunner <[hidden email]>
> Hi! So im using Jackson Pojo with Jersey and my resource class method returns
> a list of objects with the root name "List":
>
> Resource Class:
>
> @Path("/Organicas")
> public class OrganicasResource {
>
>
> public OrganicasResource() {
> }
>
> @GET
> @Produces(MediaType.APPLICATION_JSON)
> @Path("/getAllOrganicas")
> //_at_JsonProperty("Organicas")
> public List<OrganicaMobileEntity> getOrganicas(){
>
> List<OrganicaMobileEntity> organicas= new
> ArrayList<OrganicaMobileEntity>();
> //dummy data
> organicas.add(fillOrganica(123,"Organica Power","2010-12-23"));
> organicas.add(fillOrganica(124,"Organica Mind","2000-05-21"));
> organicas.add(fillOrganica(125,"Organica Strength","2002-12-23"));
> organicas.add(fillOrganica(126,"Organica Stamina","2011-06-14"));
> organicas.add(fillOrganica(127,"Organica Luck","2006-02-01"));
> organicas.add(fillOrganica(128,"Organica Love","2003-04-07"));
>
>
> return organicas;
> }
>
> private OrganicaMobileEntity fillOrganica(int id, String designacao, String
> dataAlteracao){
>
> OrganicaMobileEntity org= new OrganicaMobileEntity();
> org.setDataAlteracao(dataAlteracao);
> org.setDesignacao(designacao);
> org.setId(id);
>
> return org;
> }
> }
>
> Pojo Class:
>
> @XmlRootElement( name = "Organica" )
> public class OrganicaMobileEntity {
>
> private int id;
> private String designacao;
> private String dataAlteracao;
>
>
> public OrganicaMobileEntity() {
> super();
> }
>
> public OrganicaMobileEntity(int id, String designacao,
> String dataAlteracao) {
>
> super();
> this.id = id;
> this.designacao = designacao;
> this.dataAlteracao = dataAlteracao;
> }
>
> public String getDataAlteracao() {
> return dataAlteracao;
> }
>
> public void setDataAlteracao(String dataAlteracao) {
> this.dataAlteracao = dataAlteracao;
> }
>
> public void setId(int id) {
> this.id = id;
> }
>
> public int getId() {
> return id;
> }
>
> public void setDesignacao(String designacao) {
> this.designacao = designacao;
> }
> public String getDesignacao() {
> return designacao;
> }
>
> }
>
> JSON result:
>
> {
> "List" : [ { --> How to change this?
> "designacao" : "Organica Power",
> "dataAlteracao" : "2010-12-23",
> "id" : 123
> }, {
> "designacao" : "Organica Mind",
> "dataAlteracao" : "2000-05-21",
> "id" : 124
> }, {
> "designacao" : "Organica Strength",
> "dataAlteracao" : "2002-12-23",
> "id" : 125
> }, {
> "designacao" : "Organica Stamina",
> "dataAlteracao" : "2011-06-14",
> "id" : 126
> }, {
> "designacao" : "Organica Luck",
> "dataAlteracao" : "2006-02-01",
> "id" : 127
> }, {
> "designacao" : "Organica Love",
> "dataAlteracao" : "2003-04-07",
> "id" : 128
> } ]
> }
>
> How can i change the "List" root name value???
>
> regards,
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/how-to-rename-XmlRootElement-in-JSON-tp6173292p6403122.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://jersey.576304.n2.nabble.com/how-to-rename-XmlRootElement-in-JSON-tp6173292p6408909.html
> To unsubscribe from how to rename XmlRootElement in JSON, click here.
>
>
> View this message in context: Re: how to rename XmlRootElement in JSON
> Sent from the Jersey mailing list archive at Nabble.com.