Segundo ao Json, todos os campos foram preenchidos, mas ocorre o seguinte erro:
{
"id": 1,
"email": null,
"password": null,
"createdAccount": "2023-07-25T19:04:28",
"employee": null
}
do Json post:
{
"email": "BillGates@Outlook.com",
"password": "Microsoft",
"employee": {
"fullname": "William Gates",
"position": "CEO",
"salary": 155,
"gender": 1,
"status": 2,
"address": {
"city": "New York",
"state": "California",
"street": "csadsadas",
"postalCode": "321332-12"
}
}
}
Coloquei alguns debbuger ao resource e antes do dto ser mapeado:
AccountDTO[email=BillGates@Outlook.com, password=Microsoft, employee=EmployeeDTO[fullname=William Gates, position=CEO, salary=155.0, gender=OTHER, status=VACATION, address=AddressDTO[city=New York, state=California, street=csadsadas, postalCode=321332-12]]]
Após o dto for mapeado, ocorre o seguinte falhamento:
Account [id=null, email=null, password=null, createdAccount=2023-07-25T19:04:28.701888600Z, employee=null]
Sendo que todas as classes estão com getters e setters e os dtos foram criado em record, mas com parametros seguindo a ordeme exata. Não sei o que pode resolver isso.
A classe do modelmapper:
package com.viegasb.webapi.services.impl;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import com.viegasb.webapi.dtos.AccountDTO;
import com.viegasb.webapi.dtos.AddressDTO;
import com.viegasb.webapi.dtos.EmployeeDTO;
import com.viegasb.webapi.entities.Account;
import com.viegasb.webapi.entities.Address;
import com.viegasb.webapi.entities.Employee;
import com.viegasb.webapi.services.MapperService;
@Service
public class MapperServiceImpl implements MapperService {
private final ModelMapper mapper;
public MapperServiceImpl(ModelMapper mapper) { this.mapper = mapper; }
@Override
public Account convertToDto(AccountDTO entity) { return mapper.map(entity, Account.class); }
@Override
public Employee convertToDto(EmployeeDTO entity) { return mapper.map(entity, Employee.class); }
@Override
public Address convertToDto(AddressDTO entity) { return mapper.map(entity, Address.class); }
}
e a configuração do mapper, va se precisa:
package com.viegasb.webapi.config;
import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ModelMapperConfig {
@Bean
public ModelMapper modelMapper() { return new ModelMapper(); }
}