Java @JsonProperty未申请BeanRapper

Java @JsonProperty未申请BeanRapper,java,spring,jackson,objectmapper,Java,Spring,Jackson,Objectmapper,在CreateFlowObjectMapper中,如果传递了“first\u name”和“last\u name”,则强制转换工作正常。我正在更新流程。我只需要将有效负载数据修补到现有的DB数据 我的POJO: public class Contact { @JsonProperty( "first_name" ) @JsonView( ContactViews.CommonFields.class ) private String firstName; @J

在CreateFlowObjectMapper中,如果传递了“first\u name”和“last\u name”,则强制转换工作正常。我正在更新流程。我只需要将有效负载数据修补到现有的DB数据

我的POJO:

public class Contact
{
    @JsonProperty( "first_name" )
    @JsonView( ContactViews.CommonFields.class )
    private String firstName;

    @JsonProperty( "last_name" )
    @JsonView( ContactViews.CommonFields.class )
    private String lastName;

    public String getFirstName()
        {
            return firstName;
        }

    public void setFirstName( String firstName )
        {       
            this.firstName = firstName;
        }

    public String getLastName()
        {
            return lastName;
        }

    public void setLastName( String lastName )
        {
            this.lastName = lastName;
        }
}
 Contact contact = mapper.readerWithView( ContactViews.CommonFields.class ).forType( Contact.class ).readValue( mapper.writeValueAsString( payloadMap ) );
假设我现有的联系人只有“名字”。我需要用“姓氏”来更新它。我正在接收map形式的有效负载({“last_name”:“XYZ”})。如何使用有效负载映射更新现有联系人

创建的现有代码:

public class Contact
{
    @JsonProperty( "first_name" )
    @JsonView( ContactViews.CommonFields.class )
    private String firstName;

    @JsonProperty( "last_name" )
    @JsonView( ContactViews.CommonFields.class )
    private String lastName;

    public String getFirstName()
        {
            return firstName;
        }

    public void setFirstName( String firstName )
        {       
            this.firstName = firstName;
        }

    public String getLastName()
        {
            return lastName;
        }

    public void setLastName( String lastName )
        {
            this.lastName = lastName;
        }
}
 Contact contact = mapper.readerWithView( ContactViews.CommonFields.class ).forType( Contact.class ).readValue( mapper.writeValueAsString( payloadMap ) );
我尝试添加额外的getter和setter。它工作得很好。但我想克服这一点,因为有很多领域。任何帮助都将不胜感激

额外的getter和setter(使其工作-但我需要避免):

我正在将其用于其他函数(但如果没有额外的getter和setter,它将无法工作):

publicstaticvoidapplymapontoinstance(对象实例、映射属性)
{
if(实用程序isEmpty(属性))
返回;
字符串属性名称;
BeanRapper BeanRapper=PropertyAccessorFactory.forBeanPropertyAccess(实例);
对于(对象名称:properties.entrySet())
{
Map.Entry=(Map.Entry)名称;
propertyName=entry.getKey();
if(beanWrapper.isWritableProperty(propertyName))
setPropertyValue(propertyName,entry.getValue());
}
}
公共静态void copyValue(对象源、对象目标、Iterable属性)
{
BeanRapper src=新的BeanRapperImpl(来源);
BeanRapper trg=新BeanRapperImpl(目标);
用于(字符串propertyName:properties)
trg.setPropertyValue(propertyName,src.getPropertyValue(propertyName));
}

使用
com.fasterxml.jackson.annotation.JsonProperty
使用
com.fasterxml.jackson.annotation.JsonProperty
我只使用它,我只使用它