Autowired injects the model object and returns an error after setting the object properties in the method.

@ Controller
@ RequestMapping ("/ andy")
public class helloContoller {

@Autowired
private PayService payService;
@Autowired
private Resource resource;
@Autowired
private Person person;


@RequestMapping ("/hello2")
@ResponseBody
public Person hello2(){
    person.setAge("132");
    person.setName("andy");
    return person;
}

}

return the report:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.example.controller.Resource$$EnhancerBySpringCGLIB$$397134d0 ["$$beanFactory"]-> org.springframework.beans.factory.support.DefaultListableBeanFactory ["beanExpressionResolver"])

Mar.02,2021

public class MyMapper extends ObjectMapper{ 
    public CustomMapper() {
        this.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        //  SerializationFeature.FAIL_ON_EMPTY_BEANS  false
        this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    }
}
springmvc
<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="supportedMediaTypes">
                <list>
                    <value>application/json; charset=UTF-8</value>
                    <value>application/x-www-form-urlencoded; charset=UTF-8</value>
                </list>
            </property>
            <property name="objectMapper">
                <bean class="MyMapper">
                </bean>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
Menu