But your proposal adds a new layer in the json serialzation, i now have two
Organicas, the class organicas that contains the list and the Organicas from
the class OrganicaMobileEntity:
{
"Organicas" : {
"organicas" : [ {
"designacao" : null,
"dataAlteracao" : "2010-12-23",
"id" : 123,
"active" : true
}, {
"designacao" : "Organica Mind",
"dataAlteracao" : "2000-05-21",
"id" : 124,
"active" : false
}, {
"designacao" : "Organica Strength",
"dataAlteracao" : "2002-12-23",
"id" : 125,
"active" : true
}, {
"designacao" : "Organica Stamina",
"dataAlteracao" : "2011-06-14",
"id" : 126,
"active" : true
}, {
"designacao" : "Organica Luck",
"dataAlteracao" : "2006-02-01",
"id" : 127,
"active" : false
}, {
"designacao" : "Organica Love",
"dataAlteracao" : "2003-04-07",
"id" : 128,
"active" : false
} ]
}
}
2011/5/27 João Rossa <joao.rossa_at_gmail.com>
> 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] <
> ml-node+6408909-203917133-73314_at_n2.nabble.com> 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]<http://user/SendEmail.jtp?type=node&node=6408909&i=0>
>> >
>>
>>> 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<http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=6173292&code=am9hby5yb3NzYUBnbWFpbC5jb218NjE3MzI5MnwyMDYzODA1MDkw>.
>>
>>
>
>
--
View this message in context: http://jersey.576304.n2.nabble.com/how-to-rename-XmlRootElement-in-JSON-tp6173292p6410444.html
Sent from the Jersey mailing list archive at Nabble.com.