Question

I have 2 java application. Soap server (jax-ws) and soap client. Soap server use spring mongo and mongoDb as database. So, On my Server I have method that reterns all companies

@WebMethod(operationName = "getCompanies")
public CompanyList getCompanies(){
    CompanyList companyList = new CompanyList();
    companyList.companyDocArrayList = Lists.newArrayList(orgStructService.getCompanyDocService().findAll());
    return companyList;
}

companyList class

public class CompanyList {
    public ArrayList<CompanyDoc> companyDocArrayList;
}

And CompanyDoc

public class CompanyDoc{
    @Id
    private ObjectId id;
    private String companyName;
//getter setter
}

So, when I call this method

 ClientService clientService = new ClientService Service().getClientServicePort();
        modelMap.addAttribute("companyList", clientService.getCompanies().getCompanyDocArrayList());

In clientService.getCompanies() in List I get strange objectId like com.web.client.services.ws.ObjectId@45ee7ab1 (45ee7ab1 - this value change every refresh page) But in database it is 5369fefa1d6e6712866daaea

What I am doing wrong?

Was it helpful?

Solution

It seem that JAX-WS don't know how to convert the ObjectId object to a String. I don't know how you are using your documents, but I think that you can use a String instead of an ObjectId in your CompanyDoc object. Spring data will convert your String to an ObjectId when your inserting data and vice versa.

public class CompanyDoc{
    @Id
    private String id;
    private String companyName;
//getter setter
}

More info from the documentation

The following outlines what type conversion, if any, will be done on the property mapped to the _id document field when using the MappingMongoConverter, the default for MongoTemplate.

  • An id property or field declared as a String in the Java class will be converted to and stored as an ObjectId if possible using a Spring
    Converter. Valid conversion rules are delegated to
    the Mongo Java driver. If it cannot be converted to an ObjectId, then the value will be stored as a string in the database.
  • An id property or field declared as BigInteger in the Java class will be converted to and stored as an ObjectId using a Spring
    Converter.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top