2013-10-31 5 views
0

Guzzle에서 사용자 지정 serialization을하고 싶습니다.사용자 정의 Guzzle serialization

나는 POSTapplication/json 요청을하고 있어요,하지만 내 목적은, 처음에 그 이름 (professionalSession)에 연재되는 예 : 내가 전화를 노력하고있어 REST API를 사용하여 일치하지 않는

{ 
professionalSession : 
    { 
    param1 : "asdf", 
    param2 : "jkl;", 
    ... 
    } 
} 

. (className은 매개 변수 중 하나로 숨김). 내가 serviceDescription.json를 사용하고 전용 (생산 JSON 혼자)의 1 개 매개 변수를 덮어 쓰려

"PostAuthentication": { 
     "httpMethod": "POST", 
     "uri": "/xxx-person-service/session", 
     "summary": "Posts the session object", 
     "type": "json", 
     "responseClass": "XXX\\WebServicesClientBundle\\Entity\\ProfessionalSession", 
     "parameters":{ 
      "session": { 
       "location": "json", 
       "required": true 
      }, 
      "session-identifier": { 
       "location": "header", 
       "required": true, 
       "sentAs": "HTTP_X_SESSION_KEY" 
      } 
     } 
    } 

:

이것은 serviceDescription.json 내 정의입니다.

body (어딘가에서 말했듯이) 매개 변수 위치를 변경하려고했지만 Content-Type이 application/json으로 올바르게 설정되지 않았습니다.

어떻게하면됩니까? 감사!

답변

1

응답이 없으므로 답장을 보내고이 문제를 해결했습니다. param의 위치를 ​​body으로 변경하면 최상위 수준의 JSON 요소가 제거되므로 좋은 접근 방식입니다.

"PostAuthentication": { 
     "httpMethod": "POST", 
     "uri": "/xxx-person-service/session", 
     "summary": "Posts the session object", 
     "responseClass": "XXX\\WebServicesClientBundle\\Entity\\ProfessionalSession", 
     "parameters":{ 
      "session": { 
       "location": "body", 
       "required": true 
      }, 
      "session-identifier": { 
       "location": "header", 
       "required": true, 
       "sentAs": "HTTP_X_SESSION_KEY" 
      }, 
      //THIS is what you need: 
      "content-type": { 
       "location": "header", 
       "static": true, 
       "required" : true, 
       "default" : "application/json", 
       "sentAs" : "Content-Type" 
      } 
     } 
    }, 
:

application/json에 요청을 변경하려면이 serviceDescription.json에 다음과 같은 설명을 사용할 수 있습니다 - (이 목구멍이 동작하는 방식입니다 이것은 여전히 ​​문제로 신호 만했다.)

관련 문제