diff --git a/pom.xml b/pom.xml
index 559e5816563b7711e777522f26edcc0aaa846f1f..81f7c1c9f3b3a2405701d30f41eeb825a57fd107 100644
--- a/pom.xml
+++ b/pom.xml
@@ -130,11 +130,7 @@
             <artifactId>springfox-boot-starter</artifactId>
             <version>${springfox-swagger.version}</version>
         </dependency>
-        <dependency>
-            <groupId>com.google.code.findbugs</groupId>
-            <artifactId>jsr305</artifactId>
-            <version>${jsr305.version}</version>
-        </dependency>
+
         <dependency>
             <groupId>org.openapitools</groupId>
             <artifactId>jackson-databind-nullable</artifactId>
@@ -250,6 +246,8 @@
                     </to>
                 </configuration>
             </plugin>
+
+
             <plugin>
                 <groupId>org.openapitools</groupId>
                 <artifactId>openapi-generator-maven-plugin</artifactId>
@@ -264,8 +262,9 @@
                         <configuration>
                             <inputSpec>${project.basedir}/src/main/resources/api-docs.json</inputSpec>
                             <modelPackage>org.springframework.samples.petclinic.dto</modelPackage>
-                            <generatorName>java</generatorName>
-                            <library>resttemplate</library>
+                            <generatorName>spring</generatorName>
+                            <library>spring-boot</library>
+
                             <!-- Only enabling model generation -->
                             <modelNameSuffix>Dto</modelNameSuffix>
                             <generateApiTests>false</generateApiTests>
@@ -277,8 +276,11 @@
                             <generateSupportingFiles>false</generateSupportingFiles>
                             <!-- Activating JAVA8 features -->
                             <configOptions>
-                                <dateLibrary>java8</dateLibrary>
+                                <performBeanValidation>true</performBeanValidation>
+                                <dateLibrary>legacy</dateLibrary>
                                 <java8>true</java8>
+                                <openApiNullable>false</openApiNullable>
+                                <serializationLibrary>jackson</serializationLibrary>
                             </configOptions>
                             <!-- override the default library to jersey2 -->
                         </configuration>
diff --git a/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java b/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java
index 6af9b4e6b2b7a96cd8306aac51c552695dbbc68f..9c0474c6c8ab6c7cff0cf456946acbd547c4ee36 100755
--- a/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java
+++ b/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java
@@ -1,8 +1,12 @@
 package org.springframework.samples.petclinic.mapper;
 
 import org.mapstruct.Mapper;
+import org.springframework.samples.petclinic.dto.OwnerDto;
 import org.springframework.samples.petclinic.dto.PetDto;
+import org.springframework.samples.petclinic.dto.PetTypeDto;
+import org.springframework.samples.petclinic.model.Owner;
 import org.springframework.samples.petclinic.model.Pet;
+import org.springframework.samples.petclinic.model.PetType;
 
 import java.util.Collection;
 
@@ -10,4 +14,10 @@ import java.util.Collection;
 public interface PetMapper {
     PetDto toPetDto(Pet pet);
     Collection<PetDto> toPetsDto(Collection<Pet> pets);
+    Collection<Pet> toPets(Collection<PetDto> pets);
+    Pet toPet(PetDto petDto);
+    PetTypeDto toPetTypeDto(PetType petType);
+    PetType toPetType(PetTypeDto petTypeDto);
+    Collection<PetTypeDto> toPetTypeDtos(Collection<PetType> petTypes);
+    Owner toOwner(OwnerDto ownerDto);
 }
diff --git a/src/main/java/org/springframework/samples/petclinic/model/Pet.java b/src/main/java/org/springframework/samples/petclinic/model/Pet.java
index 329f71872dd4f9a51188e45c79bedc35157d2fd0..d26a73dab9f6ccfe628e3e7bc1d25c741853ce1a 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/Pet.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/Pet.java
@@ -36,8 +36,6 @@ import javax.persistence.TemporalType;
 import org.springframework.beans.support.MutableSortDefinition;
 import org.springframework.beans.support.PropertyComparator;
 import org.springframework.format.annotation.DateTimeFormat;
-import org.springframework.samples.petclinic.rest.JacksonCustomPetDeserializer;
-import org.springframework.samples.petclinic.rest.JacksonCustomPetSerializer;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -52,8 +50,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
  */
 @Entity
 @Table(name = "pets")
-@JsonSerialize(using = JacksonCustomPetSerializer.class)
-@JsonDeserialize(using = JacksonCustomPetDeserializer.class)
 public class Pet extends NamedEntity {
 
     @Column(name = "birth_date")
diff --git a/src/main/java/org/springframework/samples/petclinic/rest/JacksonCustomPetDeserializer.java b/src/main/java/org/springframework/samples/petclinic/rest/JacksonCustomPetDeserializer.java
deleted file mode 100644
index d879e88ee2439c2dd0145a13ce96bec2ab6d5ef8..0000000000000000000000000000000000000000
--- a/src/main/java/org/springframework/samples/petclinic/rest/JacksonCustomPetDeserializer.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.samples.petclinic.rest;
-
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
-
-/**
- * @author Vitaliy Fedoriv
- *
- */
-
-public class JacksonCustomPetDeserializer extends StdDeserializer<Pet> {
-
-	public JacksonCustomPetDeserializer() {
-		this(null);
-	}
-
-	public JacksonCustomPetDeserializer(Class<Pet> t) {
-		super(t);
-	}
-
-	@Override
-	public Pet deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
-		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
-		Pet pet = new Pet();
-		Owner owner = new Owner();
-		PetType petType = new PetType();
-		ObjectMapper mapper = new ObjectMapper();
-		Date birthDate = null;
-		JsonNode node = parser.getCodec().readTree(parser);
-		JsonNode owner_node = node.get("owner");
-		JsonNode type_node = node.get("type");
-		owner = mapper.treeToValue(owner_node, Owner.class);
-		petType = mapper.treeToValue(type_node, PetType.class);
-		int petId = node.get("id").asInt();
-		String name = node.get("name").asText(null);
-		String birthDateStr = node.get("birthDate").asText(null);
-		try {
-			birthDate = formatter.parse(birthDateStr);
-		} catch (ParseException e) {
-			e.printStackTrace();
-			throw new IOException(e);
-		}
-
-		if (!(petId == 0)) {
-			pet.setId(petId);
-		}
-		pet.setName(name);
-		pet.setBirthDate(birthDate);
-		pet.setOwner(owner);
-		pet.setType(petType);
-		return pet;
-	}
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/rest/JacksonCustomPetSerializer.java b/src/main/java/org/springframework/samples/petclinic/rest/JacksonCustomPetSerializer.java
deleted file mode 100644
index 9abb4b86522fdf6d24691a8a3ae62c2a32c113a3..0000000000000000000000000000000000000000
--- a/src/main/java/org/springframework/samples/petclinic/rest/JacksonCustomPetSerializer.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.samples.petclinic.rest;
-
-import java.io.IOException;
-import java.text.Format;
-import java.text.SimpleDateFormat;
-
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-import org.springframework.samples.petclinic.model.Visit;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-
-/**
- * @author Vitaliy Fedoriv
- *
- */
-
-public class JacksonCustomPetSerializer extends StdSerializer<Pet> {
-
-	public JacksonCustomPetSerializer() {
-		this(null);
-	}
-
-	protected JacksonCustomPetSerializer(Class<Pet> t) {
-		super(t);
-	}
-
-	@Override
-	public void serialize(Pet pet, JsonGenerator jgen, SerializerProvider provider) throws IOException {
-		Format formatter = new SimpleDateFormat("yyyy/MM/dd");
-		jgen.writeStartObject(); // pet
-		if (pet.getId() == null) {
-			jgen.writeNullField("id");
-		} else {
-			jgen.writeNumberField("id", pet.getId());
-		}
-		jgen.writeStringField("name", pet.getName());
-		jgen.writeStringField("birthDate", formatter.format(pet.getBirthDate()));
-
-		PetType petType = pet.getType();
-		jgen.writeObjectFieldStart("type");
-		jgen.writeNumberField("id", petType.getId());
-		jgen.writeStringField("name", petType.getName());
-		jgen.writeEndObject(); // type
-
-		Owner owner = pet.getOwner();
-		jgen.writeObjectFieldStart("owner");
-		jgen.writeNumberField("id", owner.getId());
-		jgen.writeStringField("firstName", owner.getFirstName());
-		jgen.writeStringField("lastName", owner.getLastName());
-		jgen.writeStringField("address", owner.getAddress());
-		jgen.writeStringField("city", owner.getCity());
-		jgen.writeStringField("telephone", owner.getTelephone());
-		jgen.writeEndObject(); // owner
-		// write visits array
-		jgen.writeArrayFieldStart("visits");
-		for (Visit visit : pet.getVisits()) {
-			jgen.writeStartObject(); // visit
-			jgen.writeNumberField("id", visit.getId());
-			jgen.writeStringField("date", formatter.format(visit.getDate()));
-			jgen.writeStringField("description", visit.getDescription());
-			jgen.writeNumberField("pet", visit.getPet().getId());
-			jgen.writeEndObject(); // visit
-		}
-		jgen.writeEndArray(); // visits
-		jgen.writeEndObject(); // pet
-	}
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/rest/PetRestController.java b/src/main/java/org/springframework/samples/petclinic/rest/PetRestController.java
index a46caf88dc4b0bb4ac6cf9cec0e50790fd8fc2e0..7568212d3d643ced061efab167d73229e06c2300 100644
--- a/src/main/java/org/springframework/samples/petclinic/rest/PetRestController.java
+++ b/src/main/java/org/springframework/samples/petclinic/rest/PetRestController.java
@@ -16,34 +16,25 @@
 
 package org.springframework.samples.petclinic.rest;
 
-import java.util.Collection;
-
-import javax.transaction.Transactional;
-import javax.validation.Valid;
-
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.samples.petclinic.dto.PetDto;
+import org.springframework.samples.petclinic.dto.PetTypeDto;
 import org.springframework.samples.petclinic.mapper.PetMapper;
 import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
 import org.springframework.samples.petclinic.service.ClinicService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.util.UriComponentsBuilder;
 
+import javax.transaction.Transactional;
+import javax.validation.Valid;
+import java.util.Collection;
+
 /**
  * @author Vitaliy Fedoriv
- *
  */
 
 @RestController
@@ -51,86 +42,91 @@ import org.springframework.web.util.UriComponentsBuilder;
 @RequestMapping("api/pets")
 public class PetRestController {
 
-	@Autowired
-	private ClinicService clinicService;
-
-    @Autowired
-    private PetMapper petMapper;
-
-    @PreAuthorize( "hasRole(@roles.OWNER_ADMIN)" )
-	@RequestMapping(value = "/{petId}", method = RequestMethod.GET, produces = "application/json")
-	public ResponseEntity<PetDto> getPet(@PathVariable("petId") int petId){
-		PetDto pet = petMapper.toPetDto(this.clinicService.findPetById(petId));
-		if(pet == null){
-			return new ResponseEntity<PetDto>(HttpStatus.NOT_FOUND);
-		}
-		return new ResponseEntity<PetDto>(pet, HttpStatus.OK);
-	}
-
-    @PreAuthorize( "hasRole(@roles.OWNER_ADMIN)" )
-	@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
-	public ResponseEntity<Collection<Pet>> getPets(){
-		Collection<Pet> pets = this.clinicService.findAllPets();
-		if(pets.isEmpty()){
-			return new ResponseEntity<Collection<Pet>>(HttpStatus.NOT_FOUND);
-		}
-		return new ResponseEntity<Collection<Pet>>(pets, HttpStatus.OK);
-	}
-
-    @PreAuthorize( "hasRole(@roles.OWNER_ADMIN)" )
-	@RequestMapping(value = "/pettypes", method = RequestMethod.GET, produces = "application/json")
-	public ResponseEntity<Collection<PetType>> getPetTypes(){
-		return new ResponseEntity<Collection<PetType>>(this.clinicService.findPetTypes(), HttpStatus.OK);
-	}
-
-    @PreAuthorize( "hasRole(@roles.OWNER_ADMIN)" )
-	@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json")
-	public ResponseEntity<Pet> addPet(@RequestBody @Valid Pet pet, BindingResult bindingResult, UriComponentsBuilder ucBuilder){
-		BindingErrorsResponse errors = new BindingErrorsResponse();
-		HttpHeaders headers = new HttpHeaders();
-		if(bindingResult.hasErrors() || (pet == null)){
-			errors.addAllErrors(bindingResult);
-			headers.add("errors", errors.toJSON());
-			return new ResponseEntity<Pet>(headers, HttpStatus.BAD_REQUEST);
-		}
-		this.clinicService.savePet(pet);
-		headers.setLocation(ucBuilder.path("/api/pets/{id}").buildAndExpand(pet.getId()).toUri());
-		return new ResponseEntity<Pet>(pet, headers, HttpStatus.CREATED);
-	}
-
-    @PreAuthorize( "hasRole(@roles.OWNER_ADMIN)" )
-	@RequestMapping(value = "/{petId}", method = RequestMethod.PUT, produces = "application/json")
-	public ResponseEntity<Pet> updatePet(@PathVariable("petId") int petId, @RequestBody @Valid Pet pet, BindingResult bindingResult){
-		BindingErrorsResponse errors = new BindingErrorsResponse();
-		HttpHeaders headers = new HttpHeaders();
-		if(bindingResult.hasErrors() || (pet == null)){
-			errors.addAllErrors(bindingResult);
-			headers.add("errors", errors.toJSON());
-			return new ResponseEntity<Pet>(headers, HttpStatus.BAD_REQUEST);
-		}
-		Pet currentPet = this.clinicService.findPetById(petId);
-		if(currentPet == null){
-			return new ResponseEntity<Pet>(HttpStatus.NOT_FOUND);
-		}
-		currentPet.setBirthDate(pet.getBirthDate());
-		currentPet.setName(pet.getName());
-		currentPet.setType(pet.getType());
-		currentPet.setOwner(pet.getOwner());
-		this.clinicService.savePet(currentPet);
-		return new ResponseEntity<Pet>(currentPet, HttpStatus.NO_CONTENT);
-	}
-
-    @PreAuthorize( "hasRole(@roles.OWNER_ADMIN)" )
-	@RequestMapping(value = "/{petId}", method = RequestMethod.DELETE, produces = "application/json")
-	@Transactional
-	public ResponseEntity<Void> deletePet(@PathVariable("petId") int petId){
-		Pet pet = this.clinicService.findPetById(petId);
-		if(pet == null){
-			return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
-		}
-		this.clinicService.deletePet(pet);
-		return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
-	}
+    private final ClinicService clinicService;
+
+    private final PetMapper petMapper;
+
+    public PetRestController(ClinicService clinicService, PetMapper petMapper) {
+        this.clinicService = clinicService;
+        this.petMapper = petMapper;
+    }
+
+    @PreAuthorize("hasRole(@roles.OWNER_ADMIN)")
+    @RequestMapping(value = "/{petId}", method = RequestMethod.GET, produces = "application/json")
+    public ResponseEntity<PetDto> getPet(@PathVariable("petId") int petId) {
+        PetDto pet = petMapper.toPetDto(this.clinicService.findPetById(petId));
+        if (pet == null) {
+            return new ResponseEntity<PetDto>(HttpStatus.NOT_FOUND);
+        }
+        return new ResponseEntity<PetDto>(pet, HttpStatus.OK);
+    }
+
+    @PreAuthorize("hasRole(@roles.OWNER_ADMIN)")
+    @RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
+    public ResponseEntity<Collection<PetDto>> getPets() {
+        Collection<PetDto> pets = petMapper.toPetsDto(this.clinicService.findAllPets());
+        if (pets.isEmpty()) {
+            return new ResponseEntity<Collection<PetDto>>(HttpStatus.NOT_FOUND);
+        }
+        return new ResponseEntity<Collection<PetDto>>(pets, HttpStatus.OK);
+    }
+
+    @PreAuthorize("hasRole(@roles.OWNER_ADMIN)")
+    @RequestMapping(value = "/pettypes", method = RequestMethod.GET, produces = "application/json")
+    public ResponseEntity<Collection<PetTypeDto>> getPetTypes() {
+        return new ResponseEntity<Collection<PetTypeDto>>(petMapper.toPetTypeDtos(this.clinicService.findPetTypes()), HttpStatus.OK);
+    }
+
+    @PreAuthorize("hasRole(@roles.OWNER_ADMIN)")
+    @RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json")
+    public ResponseEntity<PetDto> addPet(@RequestBody @Valid PetDto petDto, BindingResult bindingResult, UriComponentsBuilder ucBuilder) {
+        BindingErrorsResponse errors = new BindingErrorsResponse();
+        HttpHeaders headers = new HttpHeaders();
+        if (bindingResult.hasErrors() || (petDto == null)) {
+            errors.addAllErrors(bindingResult);
+            headers.add("errors", errors.toJSON());
+            return new ResponseEntity<>(headers, HttpStatus.BAD_REQUEST);
+        }
+        Pet pet = petMapper.toPet(petDto);
+        this.clinicService.savePet(pet);
+        petDto.setId(pet.getId());
+        headers.setLocation(ucBuilder.path("/api/pets/{id}").buildAndExpand(petDto.getId()).toUri());
+        return new ResponseEntity<>(petDto, headers, HttpStatus.CREATED);
+    }
+
+    @PreAuthorize("hasRole(@roles.OWNER_ADMIN)")
+    @RequestMapping(value = "/{petId}", method = RequestMethod.PUT, produces = "application/json")
+    public ResponseEntity<PetDto> updatePet(@PathVariable("petId") int petId, @RequestBody @Valid PetDto pet, BindingResult bindingResult) {
+        BindingErrorsResponse errors = new BindingErrorsResponse();
+        HttpHeaders headers = new HttpHeaders();
+        if (bindingResult.hasErrors() || (pet == null)) {
+            errors.addAllErrors(bindingResult);
+            headers.add("errors", errors.toJSON());
+            return new ResponseEntity<>(headers, HttpStatus.BAD_REQUEST);
+        }
+        Pet currentPet = this.clinicService.findPetById(petId);
+        if (currentPet == null) {
+            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+        }
+        currentPet.setBirthDate(pet.getBirthDate());
+        currentPet.setName(pet.getName());
+        currentPet.setType(petMapper.toPetType(pet.getType()));
+        currentPet.setOwner(petMapper.toOwner(pet.getOwner()));
+        this.clinicService.savePet(currentPet);
+        return new ResponseEntity<>(petMapper.toPetDto(currentPet), HttpStatus.NO_CONTENT);
+    }
+
+    @PreAuthorize("hasRole(@roles.OWNER_ADMIN)")
+    @RequestMapping(value = "/{petId}", method = RequestMethod.DELETE, produces = "application/json")
+    @Transactional
+    public ResponseEntity<Void> deletePet(@PathVariable("petId") int petId) {
+        Pet pet = this.clinicService.findPetById(petId);
+        if (pet == null) {
+            return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
+        }
+        this.clinicService.deletePet(pet);
+        return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
+    }
 
 
 }
diff --git a/src/main/resources/api-docs.json b/src/main/resources/api-docs.json
index 55ff776ea82a6c91dae230e474a05e7eb045142d..ac696a0b507187916ee1471b35726050d1f04bbf 100755
--- a/src/main/resources/api-docs.json
+++ b/src/main/resources/api-docs.json
@@ -1080,4 +1080,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java
index 9513f34b461e84b2e98d5f997130db43245fe424..d42d2eafe9fa80237168388467045c40aed43b8f 100644
--- a/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java
@@ -25,10 +25,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.util.StdDateFormat;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,6 +39,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.mock.mockito.MockBean;
 import org.springframework.http.MediaType;
+import org.springframework.samples.petclinic.dto.OwnerDto;
+import org.springframework.samples.petclinic.dto.PetDto;
+import org.springframework.samples.petclinic.dto.PetTypeDto;
+import org.springframework.samples.petclinic.mapper.PetMapper;
 import org.springframework.samples.petclinic.model.Owner;
 import org.springframework.samples.petclinic.model.Pet;
 import org.springframework.samples.petclinic.model.PetType;
@@ -67,21 +74,24 @@ public class PetRestControllerTests {
     @Autowired
     private PetRestController petRestController;
 
+    @Autowired
+    private PetMapper petMapper;
+
     @MockBean
     protected ClinicService clinicService;
 
     private MockMvc mockMvc;
 
-    private List<Pet> pets;
+    private List<PetDto> pets;
 
     @Before
     public void initPets(){
     	this.mockMvc = MockMvcBuilders.standaloneSetup(petRestController)
     			.setControllerAdvice(new ExceptionControllerAdvice())
     			.build();
-    	pets = new ArrayList<Pet>();
+    	pets = new ArrayList<>();
 
-    	Owner owner = new Owner();
+    	OwnerDto owner = new OwnerDto();
     	owner.setId(1);
     	owner.setFirstName("Eduardo");
     	owner.setLastName("Rodriquez");
@@ -89,11 +99,11 @@ public class PetRestControllerTests {
     	owner.setCity("McFarland");
     	owner.setTelephone("6085558763");
 
-    	PetType petType = new PetType();
+    	PetTypeDto petType = new PetTypeDto();
     	petType.setId(2);
     	petType.setName("dog");
 
-    	Pet pet = new Pet();
+    	PetDto pet = new PetDto();
     	pet.setId(3);
     	pet.setName("Rosy");
     	pet.setBirthDate(new Date());
@@ -101,7 +111,7 @@ public class PetRestControllerTests {
     	pet.setType(petType);
     	pets.add(pet);
 
-    	pet = new Pet();
+    	pet = new PetDto();
     	pet.setId(4);
     	pet.setName("Jewel");
     	pet.setBirthDate(new Date());
@@ -113,7 +123,7 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testGetPetSuccess() throws Exception {
-    	given(this.clinicService.findPetById(3)).willReturn(pets.get(0));
+    	given(this.clinicService.findPetById(3)).willReturn(petMapper.toPet(pets.get(0)));
         this.mockMvc.perform(get("/api/pets/3")
         	.accept(MediaType.APPLICATION_JSON_VALUE))
             .andExpect(status().isOk())
@@ -125,7 +135,7 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testGetPetNotFound() throws Exception {
-    	given(this.clinicService.findPetById(-1)).willReturn(null);
+    	given(petMapper.toPetDto(this.clinicService.findPetById(-1))).willReturn(null);
         this.mockMvc.perform(get("/api/pets/-1")
         	.accept(MediaType.APPLICATION_JSON))
             .andExpect(status().isNotFound());
@@ -134,7 +144,7 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testGetAllPetsSuccess() throws Exception {
-    	given(this.clinicService.findAllPets()).willReturn(pets);
+    	given(this.clinicService.findAllPets()).willReturn(petMapper.toPets(pets));
         this.mockMvc.perform(get("/api/pets/")
         	.accept(MediaType.APPLICATION_JSON))
             .andExpect(status().isOk())
@@ -149,7 +159,7 @@ public class PetRestControllerTests {
     @WithMockUser(roles="OWNER_ADMIN")
     public void testGetAllPetsNotFound() throws Exception {
     	pets.clear();
-    	given(this.clinicService.findAllPets()).willReturn(pets);
+    	given(this.clinicService.findAllPets()).willReturn(petMapper.toPets(pets));
         this.mockMvc.perform(get("/api/pets/")
         	.accept(MediaType.APPLICATION_JSON))
             .andExpect(status().isNotFound());
@@ -158,10 +168,13 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testCreatePetSuccess() throws Exception {
-    	Pet newPet = pets.get(0);
+    	PetDto newPet = pets.get(0);
     	newPet.setId(999);
     	ObjectMapper mapper = new ObjectMapper();
+        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
+        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
     	String newPetAsJSON = mapper.writeValueAsString(newPet);
+        System.err.println("--> newPetAsJSON="+newPetAsJSON);
     	this.mockMvc.perform(post("/api/pets/")
     		.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
     		.andExpect(status().isCreated());
@@ -170,10 +183,12 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testCreatePetError() throws Exception {
-    	Pet newPet = pets.get(0);
+    	PetDto newPet = pets.get(0);
     	newPet.setId(null);
     	newPet.setName(null);
     	ObjectMapper mapper = new ObjectMapper();
+        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
+        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
     	String newPetAsJSON = mapper.writeValueAsString(newPet);
     	this.mockMvc.perform(post("/api/pets/")
         		.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
@@ -183,10 +198,13 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testUpdatePetSuccess() throws Exception {
-    	given(this.clinicService.findPetById(3)).willReturn(pets.get(0));
-    	Pet newPet = pets.get(0);
+    	given(this.clinicService.findPetById(3)).willReturn(petMapper.toPet(pets.get(0)));
+    	PetDto newPet = pets.get(0);
     	newPet.setName("Rosy I");
     	ObjectMapper mapper = new ObjectMapper();
+        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
+        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+
     	String newPetAsJSON = mapper.writeValueAsString(newPet);
     	this.mockMvc.perform(put("/api/pets/3")
     		.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
@@ -205,10 +223,13 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testUpdatePetError() throws Exception {
-    	Pet newPet = pets.get(0);
-    	newPet.setName("");
+    	PetDto newPet = pets.get(0);
+    	newPet.setName(null);
     	ObjectMapper mapper = new ObjectMapper();
-    	String newPetAsJSON = mapper.writeValueAsString(newPet);
+        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
+        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+        String newPetAsJSON = mapper.writeValueAsString(newPet);
+
     	this.mockMvc.perform(put("/api/pets/3")
     		.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
         	.andExpect(status().isBadRequest());
@@ -217,10 +238,10 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testDeletePetSuccess() throws Exception {
-    	Pet newPet = pets.get(0);
+    	PetDto newPet = pets.get(0);
     	ObjectMapper mapper = new ObjectMapper();
     	String newPetAsJSON = mapper.writeValueAsString(newPet);
-    	given(this.clinicService.findPetById(3)).willReturn(pets.get(0));
+    	given(this.clinicService.findPetById(3)).willReturn(petMapper.toPet(pets.get(0)));
     	this.mockMvc.perform(delete("/api/pets/3")
     		.content(newPetAsJSON).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE))
         	.andExpect(status().isNoContent());
@@ -229,7 +250,7 @@ public class PetRestControllerTests {
     @Test
     @WithMockUser(roles="OWNER_ADMIN")
     public void testDeletePetError() throws Exception {
-    	Pet newPet = pets.get(0);
+    	PetDto newPet = pets.get(0);
     	ObjectMapper mapper = new ObjectMapper();
     	String newPetAsJSON = mapper.writeValueAsString(newPet);
     	given(this.clinicService.findPetById(-1)).willReturn(null);