How to send List<T> with Kvmserializable?

Asked

Viewed 89 times

0

I am implementing Kvmserializable for communication with web service with complex types.

I have a property of type List. However I am indicating the type List.class and I am not getting this list there in the webservice.

What am I doing wrong?

public class CadastrosImpGarIn implements KvmSerializable {

public int codCli;
public int codEmp;
public int codFil;
public int codMot;
public String datCol;
public String flowInstanceID;
public String flowName;
public String numDoc;
public List<CadastrosImpGarInTabBat> tabBat;

@Override
public Object getProperty(int index) {
    switch (index) {
    case 0:
        return codCli;
    case 1:
        return codEmp;
    case 2:
        return codFil;
    case 3:
        return codMot;
    case 4:
        return datCol;
    case 5:
        return flowInstanceID;
    case 6:
        return flowName;
    case 7:
        return numDoc;
    case 8:
        return tabBat;
    default:
        return null;
    }
}

@Override
public int getPropertyCount() {
    return 8;
}

@SuppressWarnings("rawtypes")
@Override
public void getPropertyInfo(int index, Hashtable hash, PropertyInfo info) {
    switch (index) {
    case 0:
        info.type = PropertyInfo.INTEGER_CLASS;
        info.name = "codCli";
        break;
    case 1:
        info.type = PropertyInfo.INTEGER_CLASS;
        info.name = "codEmp";
        break;          
    case 2:
        info.type = PropertyInfo.INTEGER_CLASS;
        info.name = "codFil";
        break;
    case 3:
        info.type = PropertyInfo.INTEGER_CLASS;
        info.name = "codMot";
        break;
    case 4:
        info.type = PropertyInfo.STRING_CLASS;
        info.name = "datCol";
        break;
    case 5:
        info.type = PropertyInfo.STRING_CLASS;
        info.name = "flowInstanceID";
        break;
    case 6:
        info.type = PropertyInfo.STRING_CLASS;
        info.name = "flowName";
        break;
    case 7:
        info.type = PropertyInfo.STRING_CLASS;
        info.name = "numDoc";
        break;
    case 8:
        info.type = List.class;
        info.name = "tabBat";
        break;
    default:
        break;
    }
}

@SuppressWarnings("unchecked")
@Override
public void setProperty(int index, Object value) {
    switch (index) {
    case 0:
        codCli = Integer.parseInt(value.toString());
        break;
    case 1:
        codEmp = Integer.parseInt(value.toString());
        break;
    case 2:
        codFil = Integer.parseInt(value.toString());
        break;
    case 3:
        codMot = Integer.parseInt(value.toString());
        break;
    case 4:
        datCol = value.toString();
        break;
    case 5:
        flowInstanceID = value.toString();
        break;
    case 6:
        flowName = value.toString();
        break;
    case 7:
        numDoc = value.toString();
        break;
    //TODO List?        
    case 8:
        tabBat = (List<CadastrosImpGarInTabBat>) value;
        break;
    default:
        break;
    }
}

}

  • Searching seems that Kvmserializable accepts Vector, because it does not exchange the List for Vector and uses the PropertyInfo.VECTOR_CLASS?

  • I made the change to VECTOR_CLASS but still does not send the items (children) of the main structure. Some other idea?

  • Update the question code, never used the Kvmserializable, but searching saw that it supports the Collection Vector, I didn’t know if it would work.

  • 1

    Put your solution in answer form. Leaving separate what is question and what is answer, in addition to following the website template you can still help future users and earn reputation points for it.

  • @Math I put his solution in response to Community Wiki

  • @Andrey then, I thought about doing this, but I think the cool thing would be to wait a while to see if he himself was going to put the answer, because otherwise he has no chance of winning the points right? Now that it’s done let, but let’s see if the OP creates the answer authored by him, if he do then vc delete the CW, ok?

  • @Math You’re right, if he answers I delete.

  • 1

    @felipearon after you write your own answer (see how Andrey did it and do it the same) you can accept it. This will indicate that the question is solved, this is how we do it here. For more details see How and why to accept an answer?

  • 1

    @Andrey no problem!

  • @Math didn’t get it right. Anyway, I posted as an answer the solution I found to get around the problem.

  • @felipearon is that you posted the answer along with the question, and we usually separate the two, tendeu? If you want to post your answer and accept it from there.

  • @Math, but just below posted as answer the solution... or not? Now I’m confused kkk

  • @felipearon was the Andrey who edited his question, extracting his answer and putting in the answer field, hehehe.. He did it to organize, but since it was his authorship the ideal would be for you to do it yourself :)

Show 8 more comments

1 answer

0


I ended up creating the code "in the nail" using Soapobject

    SoapObject coletaEnv = new SoapObject();
    coletaEnv.addProperty("codCli", coleta.getIdCliente());
    coletaEnv.addProperty("codEmp", 1);
    coletaEnv.addProperty("codFil", 1);
    coletaEnv.addProperty("codMot", coleta.getIdMotorista());
    coletaEnv.addProperty("datCol", DateUtils.dateToString(coleta.getDataHora()));
    coletaEnv.addProperty("numDoc", coleta.getProtocolo());

    for (ColetaItem item : coleta.getBaterias()) {

        SoapObject tabBat = new SoapObject(null, "tabBat");
        tabBat.addProperty("codBar", item.getCodigoBarras());
        tabBat.addProperty("codRef", item.getBateria().getReferencia());
        tabBat.addProperty("datFab", DateUtils.dateToString(item.getDataFabricacao()));
        tabBat.addProperty("datVct", DateUtils.dateToString(item.getDataVencimento()));
        tabBat.addProperty("defOri", item.getDefeito().getDescricao());
        tabBat.addProperty("desDef", item.getDefeito().getDescricao());
        coletaEnv.addSoapObject(tabBat);
    }

    String methodName = "ImpGar";

    SoapObject request = new SoapObject(WSBase.NAMESPACE, methodName);
    request.addProperty("user", "user");
    request.addProperty("password", "pass");
    request.addProperty("encryption", 0);

    PropertyInfo pi = new PropertyInfo();
    pi.setName("parameters");
    pi.setValue(coletaEnv);
    request.addProperty(pi);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.