From 83bc5c97ef21560d9ad05a0ead92174431635096 Mon Sep 17 00:00:00 2001 From: Damien Cassan Date: Mon, 18 Jul 2016 23:20:03 +0200 Subject: [PATCH] fix(http): convert objects passed to requests into a string (#10124) This remove a breaking change introduced with commit #e7a8e2757b06d572f614f53b648d2fd75df370d2 where json objects passed to requests were not converted into string. BREAKING CHANGE: The behavior in this commit is the same as before PR 7260 : the objects sent with the request are converted to a string, therefore there is no need for the user to take care of the serialization. Fixes #10073 --- modules/@angular/http/src/static_request.ts | 2 +- modules/@angular/http/test/backends/xhr_backend_spec.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/@angular/http/src/static_request.ts b/modules/@angular/http/src/static_request.ts index c4167dff57..5e305e8fb0 100644 --- a/modules/@angular/http/src/static_request.ts +++ b/modules/@angular/http/src/static_request.ts @@ -128,7 +128,7 @@ export class Request extends Body { getBody(): any { switch (this.contentType) { case ContentType.JSON: - return this.json(); + return this.text(); case ContentType.FORM: return this.text(); case ContentType.FORM_DATA: diff --git a/modules/@angular/http/test/backends/xhr_backend_spec.ts b/modules/@angular/http/test/backends/xhr_backend_spec.ts index 2ae46d62c0..35ed11aba4 100644 --- a/modules/@angular/http/test/backends/xhr_backend_spec.ts +++ b/modules/@angular/http/test/backends/xhr_backend_spec.ts @@ -9,6 +9,7 @@ import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; import {AsyncTestCompleter, SpyObject} from '@angular/core/testing/testing_internal'; import {BrowserXhr} from '../../src/backends/browser_xhr'; +import {Json} from '../../src/facade/lang'; import {XSRFStrategy} from '../../src/interfaces'; import {XHRConnection, XHRBackend, CookieXSRFStrategy} from '../../src/backends/xhr_backend'; import {provide, Injector, Injectable, ReflectiveInjector} from '@angular/core'; @@ -256,7 +257,7 @@ export function main() { var connection = new XHRConnection( new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR()); connection.response.subscribe(); - expect(sendSpy).toHaveBeenCalledWith(body); + expect(sendSpy).toHaveBeenCalledWith(Json.stringify(body)); expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'application/json'); });