Error deserializing JSON

0

I have the following error:

  

java.lang.NoClassDefFoundError: Failed resolution of: Ljava / lang /   invoke / MethodType;

The complete error below:

04-12 15:22:38.272 30650-30793/br.com.sys.life.atendimento I/HTTP_POST: 1 URL: http://somelink/rest/Agendamento/listarAgendamentos
04-12 15:22:38.272 30650-30793/br.com.sys.life.atendimento I/HTTP_POST: JSON: {"cdProfissional":4}
04-12 15:22:38.337 30650-30793/br.com.sys.life.atendimento I/HTTP_POST: Result: {"retornoMensagem":{"dsTitulo":"Listar Agendamentos.","dsMensagem":"SUCCESS.","dsStackTrace":null,"idCamada":"SUCCESS"},"retorno":[{"cdAgendamento":18,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":141,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"08:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"},{"cdAgendamento":19,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":144,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"09:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"}]}
04-12 15:22:38.344 30650-30650/br.com.sys.life.atendimento E/RecyclerView: No adapter attached; skipping layout
04-12 15:22:38.388 30650-30793/br.com.sys.life.atendimento E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
                                                                                    Process: br.com.sys.life.atendimento, PID: 30650
                                                                                    java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                                        at android.os.AsyncTask$3.done(AsyncTask.java:318)
                                                                                        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                                        at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                                        at java.lang.Thread.run(Thread.java:761)
                                                                                     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/invoke/MethodType;
                                                                                        at java.lang.Class.getDeclaredFields(Native Method)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:109)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.Gson.fromJson(Gson.java:802)
                                                                                        at com.google.gson.Gson.fromJson(Gson.java:868)
                                                                                        at com.google.gson.Gson.fromJson(Gson.java:841)
                                                                                        at br.com.sys.life.atendimento.communication_service.utils.GsonUtil.parseJsonObjectToObject(GsonUtil.java:201)
                                                                                        at br.com.sys.life.atendimento.communication_service.utils.GsonUtil.parseStringJsonToObject(GsonUtil.java:103)
                                                                                        at br.com.sys.life.atendimento.service_atendimento.BaseService.executaPost(BaseService.java:111)
                                                                                        at br.com.sys.life.atendimento.service_atendimento.services.ServiceAgendamentoVo.consultaAgendamentos1(ServiceAgendamentoVo.java:36)
                                                                                        at br.com.sys.life.atendimento.fragments.FragmentFilaAtendimento$AsyncTaskListaAtendimentos.doInBackground(FragmentFilaAtendimento.java:129)
                                                                                        at br.com.sys.life.atendimento.fragments.FragmentFilaAtendimento$AsyncTaskListaAtendimentos.doInBackground(FragmentFilaAtendimento.java:111)
                                                                                        at android.os.AsyncTask$2.call(AsyncTask.java:304)
                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                                        at java.lang.Thread.run(Thread.java:761) 
04-12 15:22:38.388 30650-30793/br.com.sys.life.atendimento E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.invoke.MethodType" on path: DexPathList[[zip file "/data/app/br.com.sys.life.atendimento-1/base.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_dependencies_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_0_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_1_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_2_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_3_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_4_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_5_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_6_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_7_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_8_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/br.com.sys.life.atendimento-1/lib/arm, /system/lib, /vendor/lib]]
                                                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                            ... 36 more
04-12 15:22:38.498 30650-30650/br.com.sys.life.atendimento W/art: Before Android 4.1, method int a

o JSON:

Result: {"retornoMensagem":{"dsTitulo":"Listar Agendamentos.","dsMensagem":"SUCCESS.","dsStackTrace":null,"idCamada":"SUCCESS"},"retorno":[{"cdAgendamento":18,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":141,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"08:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"},{"cdAgendamento":19,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":144,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"09:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"}]}

After so much head banging, I put in another item to serialize and deserialize to see if the error was going to continue, or not. The error has stopped, but obviously the method is not correct. I would like some help on how to build this method. Deserialize a list in json. follow the methods:

Creating JSON:

    /**
     * Cria uma instancia com os parametros de conversão
     *
     * @return
     */
    public static Gson createGsonObject() {

        // Formado de data alterado, outro formato não estava convertendo
        // Alterado para setar // na saída devido problema com WebService
        GsonBuilder builder = new GsonBuilder();

 ...
        //TRATAMENTO DE DOUBLE
        builder.registerTypeAdapter(Double.class, new JsonDoubleDeserializer());

        builder.registerTypeAdapter(Double.class, new JsonDoubleSerializer());

        //TRATAMENTO DE ARRAY ???????
        builder.registerTypeAdapter(List.class, new JsonDoubleDeserializer());

        builder.registerTypeAdapter(List.class, new JsonDoubleSerializer());

        Gson gson = builder.create();

        return gson;
    }

I left the double method on purpose, to illustrate what I'm doing.

Destroying double:

 // SOLUÇÃO DE PROBLEMA COM DOUBLE NÃO CONVERTIDO
    private static class JsonDoubleDeserializer implements
            JsonDeserializer<Double> {

        /*
         * (non-Javadoc)
         *
         * @see
         * com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement
         * , java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
         */
        @Override
        public Double deserialize(JsonElement arg0,
                                  java.lang.reflect.Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {

            String value = arg0.getAsJsonPrimitive().getAsString();

            return new Double(value);
        }
    }

/**
 * Deserialização de Double Java
 */
private static class JsonDoubleSerializer implements JsonSerializer<Double> {

    @Override
    public JsonElement serialize(Double aDouble, java.lang.reflect.Type type, JsonSerializationContext jsonSerializationContext) {
        if (aDouble == aDouble.longValue())
            return new JsonPrimitive(aDouble.longValue());
        return new JsonPrimitive(aDouble);
    }
}

This method below, when including, this posted error, stops. But, there is no data conversion, if this is the same question, I would like some help to put this method together, thank you!

Array:

private static class JsonArraySerializer implements JsonSerializer<ArrayList<Object>> {

    @Override
    public JsonElement serialize(ArrayList arrayList, java.lang.reflect.Type type, JsonSerializationContext jsonSerializationContext) {
        Gson gson = new Gson();
        arrayList = gson.fromJson(arrayList, new TypeToken<List<Object>>(){}.getType());//error cannot resolve method
        return // o que eu retorno?? //error
    }
}

// SOLUÇÃO ARRAAYY?????
private static class JsonArrayDeserializer implements
        JsonDeserializer<ArrayList> {

    @Override
    public ArrayList deserialize(JsonElement arg0,
                               java.lang.reflect.Type arg1, JsonDeserializationContext arg2)
            throws JsonParseException {
        try {
            String value = arg0.getAsJsonPrimitive().getAsString();

            return //o que eu retorno
        } catch (ClassCastException e) {
            throw new JsonParseException("Cannot parse json Boolean '"
                    + arg0.toString() + "'", e);
        }
    }
}

Fragment:

private class AsyncTaskListarAgendamentos extends BaseAsyncTask<ProfissionalVo,Void,AsyncTaskResult<RetornoAgendamentoVo>>{

    private FragmentManager mFragmentManager;
    private ProfissionalVo profissionalVo;

    public AsyncTaskListarAgendamentos(FragmentManager fragmentManager, boolean isDialogShow) {
        super(fragmentManager, isDialogShow);
        this.mFragmentManager = fragmentManager;
    }

    @Override
    protected AsyncTaskResult doInBackground(ProfissionalVo... profissionalVos) {

        try {
            profissionalVo = profissionalVos[0];

            RetornoAgendamentoVo retorno = ServiceAgendamentoVo.getInstance(MyApplicationInstance.getInstanceApplicationSingleton().getDsChaveAcessoWbs())
                    .consultaAgendamentos1(profissionalVo);

            return new AsyncTaskResult<RetornoAgendamentoVo>(retorno);
        }catch (Exception e){
            return new AsyncTaskResult<Retorno>(e);
        }
    }

    @Override
    protected void onPostExecute(AsyncTaskResult<Retorno> respProfissionalVO) {
        super.onPostExecute(respProfissionalVO);

        if (respProfissionalVO.getExceptionResult() == null && getActivity() != null){
            retornoAgendamentoVo = (RetornoAgendamentoVo) respProfissionalVO.getResult();
            agendamentoVos = new ArrayList<>();
            agendamentoVos = retornoAgendamentoVo.getRetorno();
            // specify an adapter (see also next example)
            mAdapter = new CustomRecyclerViewAdapterFila(agendamentoVos,
                    (AppCompatActivity) getActivity(), this);
        }

    }
}

Return:

public class RetornoAgendamentoVo extends Retorno{

    private List<AgendamentoVo> retorno;

    public List<AgendamentoVo> getRetorno() {
        return retorno;
    }

    public void setRetorno(List<AgendamentoVo> retorno) {
        this.retorno = retorno;
    }

}

Vo Class:

@XmlRootElement
public class AgendamentoVo implements Serializable {

    private static final long serialVersionUID = ...;
    private Long cdAgendamento;
    private ItemAgendaVo itemAgenda;
    private PacienteVo paciente;
    @XmlJavaTypeAdapter(DateAdapter.class)
... 
//getters and setters
}
    
asked by anonymous 13.04.2018 / 19:25

0 answers