首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RestTemplate返回指定对象的空字段。

RestTemplate返回指定对象的空字段。
EN

Stack Overflow用户
提问于 2017-02-16 14:12:30
回答 1查看 1.6K关注 0票数 1

我有以下try块,其中我期待来自RestTemplateexchange方法的响应:

代码语言:javascript
复制
try{            
    response = restOperations.exchange("http://localhost:8080/midpoint/ws/rest/users/00000000-0000-0000-0000-000000000002",
            HttpMethod.GET,
            new HttpEntity<String>(createHeaders("administrator", "5ecr3t")), 
            UserType.class);

    logger.info(response.getBody());
}

我期待一个UserType类型的响应,请求被正确地执行,状态为200 OK,但是UserType模型的所有字段都是空的,所以我从REST调用接收到的响应不是绑定(映射)。UserType所需的字段被注释为:

代码语言:javascript
复制
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserType", propOrder = {
    "fullName",
    "givenName",
    "familyName",
    "additionalNames",
    "locality",
    "assignment",
    "activation",
    "specialWithInternalizedName",
    "singleActivation", 
    "multiActivation",
    "multiActivationCopy",
    "singleConstruction",
    "multiConstruction",
    "multiConstructionCopy"
})

服务器响应的一个示例:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<user xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3" xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3" oid="00000000-0000-0000-0000-000000000002" version="194">
   <name>administrator</name>
   <metadata>
      <requestTimestamp>2017-01-31T14:04:14.575+01:00</requestTimestamp>
      <createTimestamp>2017-01-31T14:04:14.658+01:00</createTimestamp>
      <createChannel>http://midpoint.evolveum.com/xml/ns/public/gui/channels-3#init</createChannel>
   </metadata>
   <assignment id="1">
      <metadata>
         <requestTimestamp>2017-01-31T14:04:14.575+01:00</requestTimestamp>
         <createTimestamp>2017-01-31T14:04:14.658+01:00</createTimestamp>
         <createChannel>http://midpoint.evolveum.com/xml/ns/public/gui/channels-3#init</createChannel>
      </metadata>
      <targetRef oid="00000000-0000-0000-0000-000000000004" type="c:RoleType" />
      <activation>
         <effectiveStatus>enabled</effectiveStatus>
      </activation>
   </assignment>
   <activation>
      <administrativeStatus>enabled</administrativeStatus>
      <effectiveStatus>enabled</effectiveStatus>
      <enableTimestamp>2017-01-31T14:04:14.598+01:00</enableTimestamp>
      <lockoutStatus>normal</lockoutStatus>
   </activation>
   <iteration>0</iteration>
   <iterationToken />
   <roleMembershipRef oid="00000000-0000-0000-0000-000000000004" type="c:RoleType" />
   <fullName>midPoint Administrator</fullName>
   <givenName>midPoint</givenName>
   <familyName>Administrator</familyName>
   <credentials>
      <password>
         <lastSuccessfulLogin>
            <timestamp>2017-02-16T17:01:21.861+01:00</timestamp>
         </lastSuccessfulLogin>
         <previousSuccessfulLogin>
            <timestamp>2017-02-16T16:44:00.493+01:00</timestamp>
         </previousSuccessfulLogin>
         <metadata>
            <createTimestamp>2017-01-31T14:04:14.598+01:00</createTimestamp>
            <createChannel>http://midpoint.evolveum.com/xml/ns/public/gui/channels-3#init</createChannel>
         </metadata>
         <value>
            <t:encryptedData>
               <t:encryptionMethod>
                  <t:algorithm>http://www.w3.org/2001/04/xmlenc#aes128-cbc</t:algorithm>
               </t:encryptionMethod>
               <t:keyInfo>
                  <t:keyName>HZZUFItbX7fYQO41GT3PHJtIf2Q=</t:keyName>
               </t:keyInfo>
               <t:cipherData>
                  <t:cipherValue>SZusPiIgcrzoqDfm9uTzmrI6r4lG/OolTRIc7V/0aVo=</t:cipherValue>
               </t:cipherData>
            </t:encryptedData>
         </value>
      </password>
   </credentials>
</user>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-22 09:34:22

我解决了在pom.xml文件中添加pom.xml依赖项的问题:

代码语言:javascript
复制
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42276365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档