нет конструктора строкового аргумента / фабричного метода для десериализации из строкового значения ('1074')

Я новичок в проекте Spring DataJPA + REST, и я пытаюсь добавить нового или отредактировать работодателя из справочного EmployerType с однонаправленными отношениями OneToOne. Задача проста, но я застрял. Когда я пытаюсь добавить или отредактировать данные, я получаю такую ​​ошибку:

org.springframework.http.converter.HttpMessageNotReadableException:
Could not read document: Can not construct instance of
tr.mis.domain.EmployerType: no String-argument constructor/factory
method to deserialize from String value ('1074')  at [Source:
java.io.PushbackInputStream@6d856887; line: 1, column: 609] (through
reference chain: tr.mis.domain.Employer["employerType"]); nested
exception is com.fasterxml.jackson.databind.JsonMappingException: Can
not construct instance of tr.mis.domain.EmployerType: no
String-argument constructor/factory method to deserialize from String
value ('1074')

Ниже представлена ​​информация о классах.

@Entity
@Table(name = "employer")
public class Employer implements Serializable  {
    @GenericGenerator(
            name = "wikiSequenceGenerator",
            strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
            parameters = {
                    @Parameter(name = "sequence_name", value = "WIKI_SEQUENCE"),
                    @Parameter(name = "initial_value", value = "1000"),
                    @Parameter(name = "increment_size", value = "1")
            }
    )
    @Id
    @GeneratedValue(generator = "wikiSequenceGenerator")
    private Long employerId;
    private String uid;
    private String name;
    private String address;
    private String headName;
    
    //@JsonIgnore
    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   // @PrimaryKeyJoinColumn
    @JoinColumn(name = "employer_type_id")
    private EmployerType employerType;

    //Getters and Setters

EmployerType класс

 @Entity
    @Table(name = "employertype")
    
    public class EmployerType {
        @GenericGenerator(
                name = "wikiSequenceGenerator",
                strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
                parameters = {
                        @Parameter(name = "sequence_name", value = "WIKI_SEQUENCE"),
                        @Parameter(name = "initial_value", value = "1000"),
                        @Parameter(name = "increment_size", value = "1")
                }
        )
        @Id
        @GeneratedValue(generator = "wikiSequenceGenerator")

        private Long employerTypeId; 
        private String uid; 
        private String employerTypeName;
    
    //Getters and Setters

Регулятор отдыха

@RequestMapping(value = "/employers", method = RequestMethod.PUT)
    public Employer updateEmployer(@RequestBody Employer employer) {

        return employerRepository.save(employer);
        
    }

person Ruslan    schedule 30.03.2018    source источник
comment
См. Мои связанные вопросы: 1, 2, может они помогут ...   -  person Cepr0    schedule 30.03.2018
comment
Просто удали @JoinColumn(name = "employer_type_id"). Он должен работать   -  person atul ranjan    schedule 30.03.2018


Ответы (1)


Я исправил эту проблему, добавив конструктор String в класс EmployerType.

 public EmployerType(String employerTypeName) {
        // TODO Auto-generated constructor stub
    }
person Ruslan    schedule 16.04.2018