Type mismatch: can not convert from Unmarshaller to Pool.Unmarshaller

0

I'm getting this error message in eclipse in a Rest project

client.java code

package cliente;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import com.sun.xml.internal.ws.util.Pool.Unmarshaller;

import domain.Banda;
import domain.Musica;

public class Cliente {

    private static int HTTP_COD_SUCESSO = 200;

    public static void main(String[] args) throws JAXBException {

        try {

            URL url = new URL("http://localhost:8080/musicApp/banda/get");
            HttpURLConnection con = (HttpURLConnection) url.openConnection();

            if (con.getResponseCode() != HTTP_COD_SUCESSO) {
                throw new RuntimeException("HTTP error code : "+ con.getResponseCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader((con.getInputStream())));

            JAXBContext jaxbContext = JAXBContext.newInstance(Banda.class);

            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            Banda banda = (Banda) jaxbUnmarshaller.unmarshal(br);

            System.out.println("------  Dados da Banda  -------- \n");
            System.out.println("Nome da Banda : "+banda.getNome());
            System.out.println("Nome do Álbum : "+banda.getAlbum().getNome());
            System.out.println("Ano de Lançamento: "+banda.getAlbum().getAno());

            int count = 1;

            for (Musica musica : banda.getAlbum().getMusicas()) {
                System.out.println("Música "+ count +": "+ musica.getNome());
                count++;    
            }

            con.disconnect();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Error Image:

    
asked by anonymous 17.08.2018 / 23:23

1 answer

1

createUnmarshaller() method of class javax.xml.bind.JAXBContext returns a javax.xml.bind.Unmarshaller .

But in your code you made import of another class (which has the same name but is in another package):

import com.sun.xml.internal.ws.util.Pool.Unmarshaller;

Just swap for:

import javax.xml.bind.Unmarshaller;
    
18.08.2018 / 01:07