I'm using Spring Boot, and i have the next problem:
Have a class model:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ModelPessoa extends UtilBaseEntities<long>// . . .
The Entity:
@Entity
@Table(name = "aluno")
public class EntityAluno extends ModelPessoa / / . . .
and the class User with person (pessoa):
@Entity
@Table(name = "usuario")
public class EntityUsuario extends UtilBaseEntities<long> / / . . .
@OneToOne
@JoinColumn(name = "id_pessoa")
private ModelPessoa pessoa;
but.. when save with my Controller:
@RestController
public class ControllerAluno {
@Autowired IRepositoryAluno repository;
@RequestMapping(value = "/alunoInserir", method = RequestMethod.POST, consumes = "application/json")
public EntityAluno inserir(@RequestBody EntityAluno aluno, HttpSession sessao) {
repository.save(aluno);
return aluno;
}
With this JSON:
{"login":"8","senha":"8","pessoa":{"nome":"asd","email":"sdf","telefone":"32"},"matricula":"22"}
Have the error (in advanced rest client of chrome):
status: 400
error: "Bad Request"
exception: "org.springframework.http.converter.HttpMessageNotReadableException"
message: "Could not read JSON: Template must not be null or empty! (through reference chain: br.com.qrbibliokode.model.entities.EntityUsuario["pessoa"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: br.com.qrbibliokode.model.entities.EntityUsuario["pessoa"])"
The project is here: https://github.com/felansu/Qr-BiblioKode-Ws
What is the problem? Thanks
I resolved this problem updating the ModelPessoa entity:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "tipo")
@JsonSubTypes({
@Type(name = "aluno", value = EntityAluno.class),
@Type(name = "funcionario", value = EntityFuncionario.class),
@Type(name = "autor", value = EntityAutor.class)
})
public abstract class ModelPessoa extends UtilBaseEntities<Long> {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.