JAX-RS Rename the Set

-1

I created a project using JAX-RS to make a web service REST and it works, I can access the result in a resource and everything else but it looks like this:

{
  "carroes": {
    "carro": [
      {
        "@id": "1",
        "modelo": "Gol",
        "marca": "VW",
        "ano": 1995
      },
      {
        "@id": "2",
        "modelo": "Golf",
        "marca": "VW",
        "ano": 2010
      },
      {
        "@id": "3",
        "modelo": "Brasilia",
        "marca": "VW",
        "ano": 1984
      },
      {
        "@id": "4",
        "modelo": "Passat Variant",
        "marca": "VW",
        "ano": 1979
      },
      {
        "@id": "5",
        "modelo": "Passat",
        "marca": "VW",
        "ano": 1978
      }
    ]
  }
}

The problem is the name of the set, carroes , should be carros .

The strange thing is that I have not set carroes anywhere, at least I do not remember having put that name anywhere. Does anyone know where I can change this name?

Look how this is my Service:

@Path("/carros")
@Produces({MediaType.APPLICATION_JSON + ";charset=UTF-8", MediaType.APPLICATION_XML + ";charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON + ";charset=UTF-8", MediaType.APPLICATION_XML + ";charset=UTF-8"})
public class CarroService {

    private static CarroDAO carroDao = new CarroDAO();

    @GET        
    public List<Carro> listarCarros(){      
        List<Carro> carrosList = carroDao.findAll();    
        return carrosList;
    }


    @GET
    @Path("{id}")
    public Carro buscaCarroID(@PathParam("id") int id){
        Carro carro = carroDao.findById(id);

        return carro;
    }

    @GET
    @Path("/modelo/{nome}")
    public List<Carro> findCarrosForName(@PathParam("nome") String nome){
        List<Carro> carros = carroDao.findCarrosForName(nome);
        return carros;
    }


    @DELETE
    @Path("{id}")
    public ResponseBuilder deletarCarro(@PathParam("id") int id){
        carroDao.delete(id);

        return Response.ok("Carro Excluido");
    }   
}
    
asked by anonymous 04.01.2017 / 18:17

1 answer

0

The carriage attribute is probably coming from your "Car" model, when JAX-RS converts (serializes) to JSON it by default uses the same name as its attributes.

    
08.08.2017 / 05:20