java - 从soap web服务返回ObjectId

标签 java spring web-services mongodb soap

我有2个java应用程序。 Soap 服务器 (jax-ws) 和 Soap 客户端。 Soap服务器使用spring mongo和mongoDb作为数据库。 所以,在我的服务器上,我有返回所有公司的方法

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

公司列表类

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

和公司文档

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

所以,当我调用这个方法时

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

在列表中的 clientService.getCompanies() 中,我得到奇怪的 objectId,例如 com.web.client.services.ws.ObjectId@45ee7ab1 (45ee7ab1 - 此值每次刷新页面都会更改) 但在数据库中它是 5369fefa1d6e6712866daaea

我做错了什么?

最佳答案

似乎JAX-WS不知道如何将ObjectId对象转换为String。我不知道您如何使用文档,但我认为您可以在 CompanyDoc 对象中使用 String 而不是 ObjectId 。当您插入数据时,Spring data 会将您的 String 转换为 ObjectId,反之亦然。

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

更多信息来自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.

关于java - 从soap web服务返回ObjectId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23525747/

相关文章:

java - 正如 Joshua Bloch 在有效 Java 中所建议的那样,缓存哈希码如何在 Java 中工作?

java - org.springframework.beans.factory.UnsatisfiedDependencyException : Error creating bean with name 'bookDaoImpl'

java - URL 处的 FileNotFoundException

java - Hibernate 加入两个表并获取所有记录?

java - Spring @Required 和 @Mandatory 注解

.net - 如何使用 svcutil 从使用限制来隐藏元素的 Web 服务生成 C# WCF 代理?

java - 从 wsdl 生成 Java 代理类

java - jqGrid不显示来自java的Json数据

spring - javax.validation.ConstraintDefinitionException : HV000074 in Spring MVC

web-services - 是否可以使用 SoapUI 来测试 SPNEgo 保护的服务?