0

I have a Spring Boot Test

@RunWith(SpringRunner.class)
@WebMvcTest(controllers = MyController.class)
public class MyControllerTest {

  @Autowired
  private MockMvc mockMvc;

  @MockBean
  private MyDtoService myDtoServiceMock;

  @Test
  public void exampleTest() throws Exception {

    MyEntity entiy = new MyEntity(LocalDateTime.now().plusDays(3));
    when(myDtoServiceMock.findMyDtos()).thenReturn(singletonList(MyDto.of(entity)));

    mockMvc.perform(get("/myDtos")).andDo(print());
  }
}

When i have a look at the json printed by the test my date looks like this

"myDate":[2016,9,9,13,50,37,544000000]

If i request the same url when the app is running my date looks like this

"myDate": "2016-09-09T13:50:37"

I don't understand why the json is serialized differently.

Update to show MyDto

public class MyDto {

  private LocalDateTime myDate;

  // Getter and Setter

  public static MyDto of(MyEntity entity){

    MyDto myDto = new MyDto();
    myDto.setMyDate(entity.getMyDate());

    return myDto;
  }      

  public MyEntity toEntity() {

    //creates entity out of dto
  }
}
Yannic Bürgmann
  • 6,301
  • 5
  • 43
  • 77

0 Answers0