Avoid quoting of floating point numbers

This commit is contained in:
Axel Hodler
2018-02-08 15:24:19 +01:00
committed by Marcin Grzejszczak
parent 91d686cd52
commit 82fb1cdac3
2 changed files with 27 additions and 1 deletions

View File

@@ -164,7 +164,7 @@ abstract class BaseWireMockStubStrategy {
Map convertedMap = MapConverter.transformValues(value) {
it instanceof GString ? it.toString() : it
} as Map
return new JSONObject(convertedMap).toString()
return new JSONObject(new JsonBuilder(convertedMap).toString())
}
return new JsonBuilder(value).toString()
}

View File

@@ -0,0 +1,26 @@
package org.springframework.cloud.contract.verifier.dsl.wiremock
import org.springframework.cloud.contract.spec.Contract
import spock.lang.Specification
class WireMockResponseStubStrategySpec extends Specification {
def "should not quote floating point numbers"() {
given:
def irrelevantStatus = 200
def contract = Contract.make {
request {
}
response {
status irrelevantStatus
body([
value: 1.5
])
}
}
when:
def subject = new WireMockResponseStubStrategy(contract)
def content = subject.buildClientResponseContent()
then:
'{"value":1.5}'.equals(content.body)
}
}