2017-05-12 4 views
0

私はPOSTを使用して、obejctをパラメータとしてサービス内のメソッドに送信しています。このメソッドは毎回呼び出していますが、春は返されたオブジェクトの代わりに初期化されたオブジェクト(ゼロとヌルを持つ)を返しています。郵便配達でサービスの代わりに初期化されたオブジェクトを取得する

は、その偉大な作業:

は私が送る:

{ 
    "userId": 10, 
    "resourceType": 11, 
    "privilegeValues": [ 
    1, 
    2, 
    3 
    ] 
} 

は私が手:

{ 
    "ErrorCode": 10, 
    "ErrorDescription": null, 
    "Privilages": [ 
    1, 
    2, 
    3 
    ] 
} 

のC#:

IPrivilagesRest:

namespace RestAPI 
{ 
    [ServiceContract(Namespace = "http://microsoft.wcf.documentation")] 
    public interface IPrivilagesRest 
    { 
     [OperationContract] 
     [WebInvoke(Method = "POST", UriTemplate = "/GetUserPrivilages", RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] 
     UserPrivilegesResponse GetUserPrivilages(UserPrivilegesRequest userPrivilegesRequest); 

     [OperationContract] 
     [WebInvoke(Method = "GET", UriTemplate = "/IsAlive", RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] 
     bool isAlive(); 
    } 
} 

PrivilagesProvider:

namespace RestAPI 
{ 
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
    public class PrivilagesProvider : IPrivilagesRest 
    { 
     /// <summary> 
     /// get privilages related to a specific user. 
     /// </summary> 
     /// <param name="userPrivilegesRequest"></param> 
     /// <returns></returns> 
     public UserPrivilegesResponse GetUserPrivilages(UserPrivilegesRequest userPrivilegesRequest) 
     { 
      Console.Clear(); 
      Console.WriteLine(userPrivilegesRequest==null?"Null":"Not null!!!!!!!"); 
      return new UserPrivilegesResponse() { Privilages = new int[] { 1, 2, 3 },ErrorCode=10 }; 
     } 

     public bool isAlive() 
     { 
      return true; 
     } 
    } 
} 

Application.java

@SpringBootApplication 
public class Application { 

    private static final Logger log = LoggerFactory.getLogger(Application.class); 

    public static void main(String args[]) { 
     SpringApplication.run(Application.class); 
    } 

    @Bean 
    public RestTemplate restTemplate(RestTemplateBuilder builder) { 
     return builder.build(); 
    } 

    @Bean 
    public CommandLineRunner run(RestTemplate restTemplate) throws Exception { 
     return args -> { 
      UserPrivilegesRequest request=new UserPrivilegesRequest(); 
      UserPrivilegesResponse response = restTemplate.postForObject("http://localhost:12345/PrivilagesServiceNamespace/PrivilagesService/GetUserPrivilages",request, UserPrivilegesResponse.class); 
      log.info("respose: "+ response); 
     }; 
    } 
} 

@ToString 
public class UserPrivilegesResponse { 
    @Getter 
    @Setter 
    private int ErrorCode; 
    @Getter 
    @Setter 
    private int ErrorDescription; 
    @Getter 
    @Setter 
    private int[] Privilages; 
} 

答えて

0

WCF C#プロジェクトでわかりましたと私は同じのために異なるタイプを書いた春のJavaプロジェクトUserPrivilegesResponse.java Responseオブジェクトのプロパティです。 春はそれを解析できないので、空の初期化された(ゼロ)オブジェクトが返されました。

回答オブジェクトの各プロパティに@JsonProperty("XXX")を使用することをお勧めします。そのため、Springはどのオブジェクトを解析できないのかを教えてくれます。それは私のエラーをどのように見つけたのですか?プロパティ名がXXXと同じ場合でも使用してください。

関連する問題