Skip to content

Instantly share code, notes, and snippets.

@bclozel
Last active May 28, 2018 11:08
Show Gist options
  • Save bclozel/4e2d873e7c3999c175af9535824f818f to your computer and use it in GitHub Desktop.
Save bclozel/4e2d873e7c3999c175af9535824f818f to your computer and use it in GitHub Desktop.
repro sample for Spring Boot issue #13248
package com.example.demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureWebTestClient
public class DemoApplicationTests {
@Autowired
private WebTestClient webTestClient;
@Test
public void testUserJsonDeserialization() {
User user = this.webTestClient.get().uri("/")
.accept(MediaType.APPLICATION_JSON).exchange()
.expectBody(User.class).returnResult().getResponseBody();
assertThat(user.getName()).isEqualTo("spring");
}
}
package com.example.demo;
import javax.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
@Data
@Builder
public class User {
private String id;
@NotBlank
private String name;
@Range(min = 10,max = 100)
private Integer age;
}
package com.example.demo;
import reactor.core.publisher.Mono;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class UserController {
@GetMapping("/")
@ResponseBody
public Mono<User> fetchUser() {
return Mono.just(User.builder().age(15).name("spring").build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment