I have a simple test for my RestController. I expect $[1].parent_id return Long as an object, not an integer primitive. It will return Long if parent_id is in a long range of numbers and> integers (e.g. 2147483650L).
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @WebAppConfiguration public class TransactionServiceControllerTest { @Before public void setup() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
Result from another test:
Expected: is <12L> but: was <2147483650L> //return Long instead int
this is my JacksonConfiguration setup
@Configuration public class JacksonConfiguration { @Bean @Primary public ObjectMapper objectMapper() { final ObjectMapper objectMapper = new ObjectMapper();
And my POJO
public class Transaction { private double ammount; private String type; private Long parentId; public Transaction(Double ammount, String type, Long parentId) {
MyRestController
@RestController @RequestMapping("transaction") public class TransactionServiceController { @RequestMapping(method = RequestMethod.GET) List<Transaction> getTransaction() { return Arrays.asList( new Transaction(100d, "car", null), new Transaction(100d, "table", 12L) ); } }
And Application.java
@SpringBootApplication public class Application { public static void main(String[] args){ SpringApplication.run(Application.class,args); } }
source share